List of utility methods to do Day End
void | setTimeToEndofDay(Calendar calendar) set Time To Endof Day calendar.set(Calendar.HOUR_OF_DAY, 23); calendar.set(Calendar.MINUTE, 59); calendar.set(Calendar.SECOND, 59); calendar.set(Calendar.MILLISECOND, 999); |
Date | setTimeToEndOfDay(Date date) set Time To End Of Day Calendar c = Calendar.getInstance();
c.setTime(date);
c.set(Calendar.HOUR_OF_DAY, 23);
c.set(Calendar.MINUTE, 59);
c.set(Calendar.SECOND, 59);
c.set(Calendar.MILLISECOND, 999);
return c.getTime();
|
long | subtractSecond(Date startDate, Date endDate) subtract Second Calendar startCalendar = Calendar.getInstance(); startCalendar.setTime(startDate); long startTimeInMillis = startCalendar.getTimeInMillis(); Calendar endCalendar = Calendar.getInstance(); endCalendar.setTime(endDate); long endTimeInMillis = endCalendar.getTimeInMillis(); return (endTimeInMillis - startTimeInMillis) / 1000; |
Date | toDayEnds(Date date) Returns a Date object that represents the ending hour,min,second of a day (i.e., 23:59:59).
Calendar cal = GregorianCalendar.getInstance();
cal.setTime(date);
cal.set(Calendar.HOUR_OF_DAY, cal.getActualMaximum(Calendar.HOUR_OF_DAY));
cal.set(Calendar.MINUTE, cal.getActualMaximum(Calendar.MINUTE));
cal.set(Calendar.SECOND, cal.getActualMaximum(Calendar.SECOND));
return cal.getTime();
|
long | toDayInterval(Date startDate, Date endDate) to Day Interval return (endDate.getTime() - startDate.getTime()) / 86400000;
|
boolean | todayOnOrBetween(Date startDate, Date endDate) today On Or Between Date today = new Date(); if ((isSameDate(today, startDate) || today.after(startDate) && (isSameDate(today, endDate) || today.before(endDate)))) { return true; return false; |
long | yearsBetween(final Date startDate, final Date endDate) years Between return daysBetween(startDate, endDate) / 365l;
|