Android Utililty Methods Date Compare

List of utility methods to do Date Compare

Description

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

Method

intcompareCurrentDate(Date currentDate)
compare Current Date
return compareDate(currentDate, nowAsDate(), Calendar.DATE);
intcompareDate(Date date1, Date date2)
compare Date
return date1.compareTo(date2);
intcompareDate(Date date1, Date date2, int what)
compare Date
Calendar objCalendar1 = Calendar.getInstance();
objCalendar1.setTime(date1);
Calendar objCalendar2 = Calendar.getInstance();
objCalendar2.setTime(date2);
int iResult = compare(objCalendar1, objCalendar2, what);
if (iResult > 0) {
    return 1;
} else if (iResult < 0) {
...
intcompareDate(String date1, String date2, int what)
compare Date
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Date objDate1 = df.parse(date1);
Date objDate2 = df.parse(date2);
return compareDate(objDate1, objDate2, what);
DatedateAfterDate(Date date, long days)
date After Date
long d = date.getTime();
d += days * 86400000;
return new java.util.Date(d);
DatedateBeforeDate(Date date, long days)
date Before Date
long d = date.getTime();
d += days * 86400000;
return new java.util.Date(d);
booleanisSameDay(Date dateSource, Date dateDesti)
is Same Day
if (dateSource == null || dateDesti == null) {
    throw new IllegalArgumentException("The date must not be null");
Calendar objCalendarSource = Calendar.getInstance();
objCalendarSource.setTime(dateSource);
Calendar objCalendarDesti = Calendar.getInstance();
objCalendarDesti.setTime(dateDesti);
return isSameDay(objCalendarSource, objCalendarDesti);
...
booleanisSameInstant(Date date1, Date date2)
is Same Instant
if (date1 == null || date2 == null) {
    throw new IllegalArgumentException("The date must not be null");
return date1.getTime() == date2.getTime();
booleanneedsMidnightCountdown()
needs Midnight Countdown
int offset = getDateOffset();
return offset > 0
        || getDay() == Calendar.SUNDAY
        || (getHour() > 15 || (getHour() == 15 && getMinute() >= 15));
intdateDiffer(Date date1, Date date2)
date Differ
if (date1 == null || date2 == null)
    return 0;
return (int) ((date2.getTime() + 28800000) / 86400000 - (date1
        .getTime() + 28800000) / 86400000);