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

booleanareEqual(Date date1, Date date2)
Compares if two dates are equal up to second resolution.
boolean result = false;
if (date1 == null && date2 == null) {
    result = true;
} else if (date1 == null || date2 == null) {
    result = false;
} else {
    Calendar cal1 = Calendar.getInstance();
    Calendar cal2 = Calendar.getInstance();
...
booleandateEquals(Date dtFirst, Date dtSecond)
Check if two dates equals regardless of the time.
boolean bReturn;
bReturn = (dtFirst == dtSecond);
if (!bReturn) {
    if (dtFirst == null) {
        bReturn = (dtSecond == null);
    } else {
        if (dtSecond != null) {
            Calendar compCalendar;
...
booleandatesEqualToSecond(Date date1, Date date2)
compares two datess down to the second
Calendar calendar1 = new GregorianCalendar(GMT_TZ);
calendar1.setTime(date1);
Calendar calendar2 = new GregorianCalendar(GMT_TZ);
calendar2.setTime(date2);
if (calendar1.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR)) {
    if (calendar1.get(Calendar.DAY_OF_YEAR) == calendar2.get(Calendar.DAY_OF_YEAR)) {
        if (calendar1.get(Calendar.HOUR) == calendar2.get(Calendar.HOUR)) {
            if (calendar1.get(Calendar.MINUTE) == calendar2.get(Calendar.MINUTE)) {
...
booleanequal(Date date, Date other)
equal
Calendar c1 = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
c1.setTime(date);
Calendar c2 = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
c2.setTime(other);
return c1.getTimeInMillis() == c2.getTimeInMillis();
intequalDateByDay(Date date1, Date date2)
This is function equalDateByDay Version: 1.0 History: DATE AUTHOR DESCRIPTION ------------------------------------------------- 10-April-2013 Nam Dinh Create new
Calendar cal1 = Calendar.getInstance();
cal1.setTime(date1);
Calendar cal2 = Calendar.getInstance();
cal2.setTime(date2);
if (cal1.get(Calendar.YEAR) > cal2.get(Calendar.YEAR)) {
    return 1;
} else if (cal1.get(Calendar.YEAR) < cal2.get(Calendar.YEAR)) {
    return -1;
...
booleanequalDates(Date first, Date second)
Checks if year, month, date of two Date objects match.
Calendar calFirst = Calendar.getInstance();
Calendar calSecond = Calendar.getInstance();
calFirst.setTime(first);
calSecond.setTime(second);
return calFirst.get(Calendar.YEAR) == calSecond.get(Calendar.YEAR)
        && calFirst.get(Calendar.MONTH) == calSecond.get(Calendar.MONTH)
        && calFirst.get(Calendar.DAY_OF_MONTH) == calSecond.get(Calendar.DAY_OF_MONTH);
booleanequalsIgnoreTime(final Date d1, final Date d2)

Two dates are equal if they have the same date (differing time values will be ignored) or if d1 and d2 are both null.

if ((d1 == null) && (d2 == null)) {
    return true;
if (d1 != null && d2 != null) {
    Calendar c1 = Calendar.getInstance();
    c1.setTimeInMillis(d1.getTime());
    Calendar c2 = Calendar.getInstance();
    c2.setTimeInMillis(d2.getTime());
...
booleanequalsToDate(Date date1, Date date2, boolean checkTime)
equals To Date
Calendar cal = Calendar.getInstance();
cal.setTime(date1);
int date1Year = cal.get(Calendar.YEAR);
int date1Month = cal.get(Calendar.MONTH) + 1;
int date1Day = cal.get(Calendar.DATE);
int date1Hour = cal.get(Calendar.HOUR);
int date1Minute = cal.get(Calendar.MINUTE);
cal.setTime(date2);
...
booleanequalsWoTime(final Date date1, final Date date2)
equals Wo Time
return getZeroTimeDate(date1).equals(getZeroTimeDate(date2));
booleanfirstLessOrEqualSecond(Date firstDate, Date secondDate)
first Less Or Equal Second
Calendar firstCalendarDate = Calendar.getInstance();
firstCalendarDate.setTime(firstDate);
Calendar secondCalendarDate = Calendar.getInstance();
secondCalendarDate.setTime(secondDate);
firstCalendarDate.set(Calendar.DAY_OF_MONTH, 1);
return firstCalendarDate.compareTo(secondCalendarDate) <= 0;