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

intcompare(Date date1, Date date2)
compare
String d1 = dateToString(date1, "yyyyMMdd");
String d2 = dateToString(date2, "yyyyMMdd");
return d1.compareTo(d2);
intcompare(String date0, String date1, String format)
compare
SimpleDateFormat sd = new SimpleDateFormat(format);
try {
    long diff = sd.parse(date0).getTime()
            - sd.parse(date1).getTime();
    if (diff > 0) {
        return 1;
    } else if (diff < 0) {
        return -1;
...
booleanisDateTimeAfter(String startDate, String startTime, String endDate, String endTime)
is Date Time After
Date startD = dateTimeToDateObj(startDate, startTime);
Date endD = dateTimeToDateObj(endDate, endTime);
if (startD.getTime() >= endD.getTime()) {
    return false;
} else {
    return true;
booleanisDateNew(String YearMonthDayHourMinuteSeconds)
is Date New
boolean flag = false;
int numOfDays = -14;
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_YEAR, numOfDays);
Date fourteenDaysAgo = cal.getTime();
String expectedPattern = "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat formatter = new SimpleDateFormat(expectedPattern);
Date date;
...
booleanisSameDay(Date d1, Date d2)
is Same Day
return d1.getDay() == d2.getDay() && d1.getMonth() == d2.getMonth()
        && d1.getYear() == d2.getYear();
booleanisSameDay(Date date1, Date date2)
is Same Day
Calendar cal1 = Calendar.getInstance();
Calendar cal2 = Calendar.getInstance();
cal1.setTime(date1);
cal2.setTime(date2);
return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR)
        && cal1.get(Calendar.DAY_OF_YEAR) == cal2
                .get(Calendar.DAY_OF_YEAR);