Java Utililty Methods Date Equal

List of utility methods to do Date Equal

Description

The list of methods to do Date Equal are organized into topic(s).

Method

booleanmonthEquals(Date current, Date compare)
month Equals
Calendar curr = Calendar.getInstance();
curr.setTime(current);
Calendar cmp = Calendar.getInstance();
cmp.setTime(compare);
int year1 = curr.get(1);
int year2 = cmp.get(1);
int month1 = curr.get(2);
int month2 = cmp.get(2);
...
booleannowInDateEquals(Date now, Date d1, Date d2)
now In Date Equals
if (compareDateEquals(d1, now)) {
    return true;
} else if (compareDateEquals(d2, now)) {
    return true;
} else if (now.after(d1) && now.before(d2)) {
    return true;
return false;
...
booleansameDate(Date date1, Date date2)
Checks if the two Dates is for the same date
if (date1 == null || date2 == null) {
    return false;
return resetTime(date1).getTime() == resetTime(date2).getTime();
booleansameDate(Date date1, Date date2)
same Date
Calendar cal1 = Calendar.getInstance();
Calendar cal2 = Calendar.getInstance();
cal1.setTime(date1);
cal2.setTime(date2);
return sameDate(cal1, cal2);
booleanyearMonthsEqual(final Date firstDate, final Date secondDate)
year Months Equal
final Calendar firstCal = Calendar.getInstance();
firstCal.setTime(firstDate);
final Calendar secondCal = Calendar.getInstance();
secondCal.setTime(secondDate);
return firstCal.get(Calendar.MONTH) == secondCal.get(Calendar.MONTH)
        && firstCal.get(Calendar.YEAR) == secondCal.get(Calendar.YEAR);