List of utility methods to do Day End
int | dayBetweenTwoDates(Date beginDate, Date endDate) day Between Two Dates int days; int pnMark = 1; if (endDate != null && beginDate != null) { Calendar bCalendar = Calendar.getInstance(); Calendar eCalendar = Calendar.getInstance(); if (beginDate.after(endDate)) { pnMark = -1; bCalendar.setTime(endDate); ... |
Date | dayEnd(Date dt) Set a Date dt to the end of the day, that is, 11:59:59:999pm return the new Date. Calendar cal = Calendar.getInstance();
cal.setTime(dt);
cal.set(Calendar.HOUR_OF_DAY, 23);
cal.set(Calendar.MINUTE, 59);
cal.set(Calendar.SECOND, 59);
cal.set(Calendar.MILLISECOND, 999);
return cal.getTime();
|
Date | dayEnd(final Date date) day End 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();
|
int | daysOfTwoDate(Date beginDate, Date endDate) days Of Two Date Calendar beginCalendar = Calendar.getInstance();
Calendar endCalendar = Calendar.getInstance();
beginCalendar.setTime(beginDate);
endCalendar.setTime(endDate);
return getDaysBetween(beginCalendar, endCalendar);
|
long | dayValue(Date date, boolean startEnd) This method converts the java date into the long that point to the beginning of the day. Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.HOUR, startEnd ? 0 : 23);
calendar.set(Calendar.MINUTE, startEnd ? 0 : 59);
calendar.set(Calendar.SECOND, startEnd ? 0 : 59);
calendar.set(Calendar.MILLISECOND, startEnd ? 0 : 999);
return calendar.getTime().getTime();
|
int | deltaInDays(Date start, Date end) Get the difference in number of days between the specified dates. Calendar startCal = Calendar.getInstance(); startCal.setTime(start); Calendar endCal = Calendar.getInstance(); endCal.setTime(end); clearTime(startCal); clearTime(endCal); long endL = endCal.getTimeInMillis() + endCal.getTimeZone().getOffset(endCal.getTimeInMillis()); long startL = startCal.getTimeInMillis() + startCal.getTimeZone().getOffset(startCal.getTimeInMillis()); ... |
int | deltaMonths(Date start, Date end) delta Months Calendar a = Calendar.getInstance(); a.setTime(start); int sm = a.get(Calendar.YEAR) * 12 + a.get(Calendar.MONTH); a.setTime(end); int em = a.get(Calendar.YEAR) * 12 + a.get(Calendar.MONTH); return em - sm; |
int | divMonth(Date startDate, Date enDate) div Month Calendar startCalendar = Calendar.getInstance(); startCalendar.setTime(startDate); Calendar endCalendar = Calendar.getInstance(); endCalendar.setTime(enDate); int yearDiv = startCalendar.get(Calendar.YEAR) - endCalendar.get(Calendar.YEAR); int monthDiv = startCalendar.get(Calendar.MONTH) - endCalendar.get(Calendar.MONTH); return monthDiv + yearDiv * 12; |
Date | endOfDay(Date aDate) Compute midnight of the date provided. Calendar cal = GregorianCalendar.getInstance();
cal.setTime(aDate);
cal.set(Calendar.MILLISECOND, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.HOUR_OF_DAY, 24);
Date midnight = cal.getTime();
return midnight;
...
|
Date | endOfDay(Date aDate) end Of Day Calendar cal = GregorianCalendar.getInstance();
cal.setTime(aDate);
cal.set(Calendar.MILLISECOND, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.HOUR_OF_DAY, 24);
Date midnight = cal.getTime();
return midnight;
...
|