List of utility methods to do Day Compare
boolean | isSameDay(Date date1, Date date2) Checks if two date objects are on the same day ignoring time. 28 Mar 2002 13:45 and 28 Mar 2002 06:01 would return true. if (date1 == null || date2 == null) { throw new IllegalArgumentException("The date must not be null"); Calendar cal1 = Calendar.getInstance(); cal1.setTime(date1); Calendar cal2 = Calendar.getInstance(); cal2.setTime(date2); return isSameDay(cal1, cal2); ... |
boolean | isSameDay(Calendar cal1, Calendar cal2) Checks if two calendar objects are on the same day ignoring time. 28 Mar 2002 13:45 and 28 Mar 2002 06:01 would return true. if (cal1 == null || cal2 == null) { throw new IllegalArgumentException("The date must not be null"); return (cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA) && cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal1 .get(Calendar.DAY_OF_YEAR) == cal2 .get(Calendar.DAY_OF_YEAR)); |
int | daysSince(long date) days Since final Calendar logDate = Calendar.getInstance(); logDate.setTimeInMillis(date); logDate.set(Calendar.SECOND, 0); logDate.set(Calendar.MINUTE, 0); logDate.set(Calendar.HOUR_OF_DAY, 0); final Calendar today = Calendar.getInstance(); today.set(Calendar.SECOND, 0); today.set(Calendar.MINUTE, 0); ... |
boolean | isDateDayEqual(long lTime1, long lTime2) is Date Day Equal Calendar cal1 = Calendar.getInstance();
cal1.setTimeInMillis(lTime1);
Calendar cal2 = Calendar.getInstance();
cal2.setTimeInMillis(lTime2);
return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR)
&& cal1.get(Calendar.DAY_OF_YEAR) == cal2
.get(Calendar.DAY_OF_YEAR);
|
int | getDaysAgo(String fromDay, int toOlderDay, int toOlderDayMonth) get Days Ago int daysAgo = 0; char charAt0 = fromDay.charAt(0); char charAt1 = fromDay.charAt(1); String sDay = "" + charAt0 + charAt1; sDay = sDay.trim(); int fromDayInt = Integer.valueOf(sDay); if (fromDayInt >= toOlderDay) { return fromDayInt - toOlderDay; ... |
boolean | isDayChanged(long lastScan) is Day Changed Date last = new Date(lastScan); Date now = new Date(); long lastlong = Date.UTC(last.getYear(), last.getMonth(), last.getDay(), 0, 0, 0); long nowlong = Date.UTC(now.getYear(), now.getMonth(), now.getDay(), 0, 0, 0); return lastlong != nowlong; |