Java Utililty Methods Day End

List of utility methods to do Day End

Description

The list of methods to do Day End are organized into topic(s).

Method

voidsetTimeToEndofDay(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);
DatesetTimeToEndOfDay(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();
longsubtractSecond(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;
DatetoDayEnds(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();
longtoDayInterval(Date startDate, Date endDate)
to Day Interval
return (endDate.getTime() - startDate.getTime()) / 86400000;
booleantodayOnOrBetween(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;
longyearsBetween(final Date startDate, final Date endDate)
years Between
return daysBetween(startDate, endDate) / 365l;