List of utility methods to do Date Compare
int | compareCurrentDate(Date currentDate) compare Current Date return compareDate(currentDate, nowAsDate(), Calendar.DATE);
|
int | compareDate(Date date1, Date date2) compare Date return date1.compareTo(date2);
|
int | compareDate(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) { ... |
int | compareDate(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); |
Date | dateAfterDate(Date date, long days) date After Date long d = date.getTime(); d += days * 86400000; return new java.util.Date(d); |
Date | dateBeforeDate(Date date, long days) date Before Date long d = date.getTime(); d += days * 86400000; return new java.util.Date(d); |
boolean | isSameDay(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); ... |
boolean | isSameInstant(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(); |
boolean | needsMidnightCountdown() needs Midnight Countdown int offset = getDateOffset(); return offset > 0 || getDay() == Calendar.SUNDAY || (getHour() > 15 || (getHour() == 15 && getMinute() >= 15)); |
int | dateDiffer(Date date1, Date date2) date Differ if (date1 == null || date2 == null) return 0; return (int) ((date2.getTime() + 28800000) / 86400000 - (date1 .getTime() + 28800000) / 86400000); |