Java Utililty Methods Day Compare

List of utility methods to do Day Compare

Description

The list of methods to do Day Compare are organized into topic(s).

Method

StringafterNDay(int n)
after N Day
Calendar c = Calendar.getInstance();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
c.setTime(new Date());
c.add(Calendar.DATE, n);
Date d2 = c.getTime();
String s = df.format(d2);
return s;
StringafterNDaysDate(String theDate, int nDayNum, String format)
after N Days Date
SimpleDateFormat sdf = new SimpleDateFormat(format);
Date dd1 = sdf.parse(theDate);
Calendar cal = Calendar.getInstance();
cal.setTime(dd1);
cal.add(Calendar.DAY_OF_YEAR, nDayNum);
sdf.setTimeZone(TimeZone.getDefault());
return (sdf.format(cal.getTime()));
intcompareDateByDay(Date date1, Date date2)
Days, compare the size of the two dates.
if (date1 == null) {
    date1 = future();
if (date2 == null) {
    date2 = future();
String d1 = dateToString(date1, DATEFORMAT_YYYYMMDD);
String d2 = dateToString(date2, DATEFORMAT_YYYYMMDD);
...
intcompareDay(Date first, Date second)

Description:Get Monday of the week the day specified by parameter belongs to

Calendar cf = Calendar.getInstance();
cf.setTime(first);
Calendar cs = Calendar.getInstance();
cs.setTime(second);
int offset = (cf.get(Calendar.YEAR) - cs.get(Calendar.YEAR)) * 12 * 30
        + (cf.get(Calendar.MONTH) - cs.get(Calendar.MONTH)) * 30
        + (cf.get(Calendar.DATE) - cs.get(Calendar.DATE));
return offset;
...
booleancompareInSameDay(Date date1, Date date2)
compare In Same Day
if (null == date1 || null == date2)
    return false;
String dateString1 = getFormateDateString(date1, format1);
String dateString2 = getFormateDateString(date2, format1);
if (dateString1.equals(dateString2)) {
    return true;
return false;
...
booleanisSameDay(Date a, Date b)
is Same Day
if (a == null || b == null) {
    return false;
Calendar ca = new GregorianCalendar();
ca.setTime(a);
Calendar cb = new GregorianCalendar();
cb.setTime(b);
return ca.get(Calendar.YEAR) == cb.get(Calendar.YEAR) && ca.get(Calendar.MONTH) == cb.get(Calendar.MONTH)
...
booleanisSameDay(Date c1, Date c2)
is Same Day
return formatDate(c1).equals(formatDate(c2));
booleanisSameDay(Date date, Date date2)
is Same Day
if (date == null || date2 == null) {
    return false;
DateFormat df = getDateFormat(YMD);
return df.format(date).equals(df.format(date2));
booleanisSameDay(Date date1, Date date2)
is Same Day
DateFormat fmt = getFormat(dateFormat);
return fmt.format(date1).equals(fmt.format(date2));
booleanisSameDay(Date date1, Date date2)
is Same Day
SimpleDateFormat sdf = new SimpleDateFormat(webFormat);
return sdf.format(date1).equals(sdf.format(date2));