List of utility methods to do Day End
Long | getEndOfDay(Long date) get End Of Day Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(date);
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
calendar.set(Calendar.MILLISECOND, 999);
return calendar.getTimeInMillis();
|
Date | getEndOfHour(Date day) Returns a Date set to the last possible millisecond of the day, just before midnight. return getEndOfHour(day, Calendar.getInstance());
|
Date | getEndOfTheDate(Date date) Precondition: date argument is not null. assert date != null; 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(); ... |
Date | getEndOfYear(Date dt) Return the End of year (last day of month & year) Hour, minutes, seconds are set to 23:59:59 if (dt == null) return null; GregorianCalendar gc = new GregorianCalendar(); gc.setTime(getStartOfYear(dt)); gc.set(Calendar.MONTH, 11); gc.setTime(getEndOfMonth(gc.getTime())); return gc.getTime(); |
Date | getEndQuaterly(Date startDate) get End Quaterly Calendar result = Calendar.getInstance();
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, startDate.getYear() + 1900);
calendar.set(Calendar.MONTH, startDate.getMonth());
calendar.set(Calendar.DATE, startDate.getDate());
if (calendar.get(Calendar.MONTH) <= Calendar.MARCH) {
result.set(Calendar.MONTH, Calendar.MARCH);
result.set(Calendar.DATE, result.getActualMaximum(Calendar.DATE));
...
|
Date | getEndSixMonthly(Date startDate) get End Six Monthly Calendar result = Calendar.getInstance();
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, startDate.getYear() + 1900);
calendar.set(Calendar.MONTH, startDate.getMonth());
calendar.set(Calendar.DATE, startDate.getDate());
if (calendar.get(Calendar.MONTH) <= Calendar.JUNE) {
result.set(Calendar.MONTH, Calendar.JUNE);
result.set(Calendar.DATE, result.getActualMaximum(Calendar.DATE));
...
|
Date | getEndTimeOfDay(Date date) get End Time Of Day Calendar calender = Calendar.getInstance();
calender.setTime(date);
setEndTimeOfDay(calender);
return calender.getTime();
|
Date | getEndTimeOfDayOrNow(Date date) Get the end time date-time of the given day which is 1 minute before midnight, unless the specified day is actually today, when the current date-time is returned Date nowDate = new Date(); Calendar nowCalendar = new GregorianCalendar(); nowCalendar.setTime(nowDate); Calendar currentCalendar = new GregorianCalendar(); currentCalendar.setTime(date); currentCalendar.set(HOUR_OF_DAY, 23); currentCalendar.set(MINUTE, 59); currentCalendar.set(SECOND, 59); ... |
int | getKalenderWoche(final Date date, final Locale locale) get Kalender Woche final Calendar calendar = Calendar.getInstance(locale); calendar.setTime(date); return calendar.get(Calendar.WEEK_OF_YEAR); |
Calendar | getLastDayEnding(Date date, int field) get Last Day Ending Calendar c = getCalendar(date);
setToEndTimeOfTheDay(c);
c.set(field, c.getActualMaximum(field));
return c;
|