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

DateendOfDayDate(Date date)
end Of Day Date
Calendar now = Calendar.getInstance();
now.setTime(date);
now.set(Calendar.HOUR_OF_DAY, 23);
now.set(Calendar.MINUTE, 59);
now.set(Calendar.SECOND, 59);
now.set(Calendar.MILLISECOND, 999);
return now.getTime();
longendOfDayInMillis(long date)
Returns the last millisecond of the specified date.
Calendar calendar = Calendar.getInstance();
synchronized (calendar) {
    calendar.setTimeInMillis(date);
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    calendar.set(Calendar.MILLISECOND, 999);
    calendar.set(Calendar.SECOND, 59);
    calendar.set(Calendar.MINUTE, 59);
    return calendar.getTimeInMillis();
...
java.util.DateendOfTheMonth(java.util.Date date, Locale locale)
end Of The Month
Calendar calendar = Calendar.getInstance(locale);
calendar.setTime(date);
calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
return calendar.getTime();
CalendarendOfYear(Date referenceDate, TimeZone timeZone)
Calcuate the date at the end of the year from the given date.
Calendar c1 = Calendar.getInstance(timeZone);
c1.setTime(referenceDate);
Calendar c2 = Calendar.getInstance();
c2.clear();
c2.set(c1.get(Calendar.YEAR) + 1, 0, 1);
c2.setTimeZone(timeZone);
return c2;
SetfillBetweenDays(Date from, Date to)
fill Between Days
Calendar c1 = dateToCalendar(from);
Calendar c2 = dateToCalendar(to);
int days = gapInDays(c1, c2);
Set<Date> fill = new TreeSet<>();
if (days > 0) {
    for (int i = 1; i < days; i++) {
        c1.add(Calendar.DAY_OF_MONTH, 1);
        fill.add(c1.getTime());
...
intgetAgeInDays(Date startDate, Date endDate)
get Age In Days
long duration = endDate.getTime() - startDate.getTime();
return (int) Math.floor(duration / DAY_IN_MILLSEC);
intgetApartDate(Date startDate, Date endDate)
get Apart Date
Calendar sd = Calendar.getInstance();
Calendar ed = Calendar.getInstance();
sd.setTime(startDate);
int day1 = sd.get(Calendar.DAY_OF_YEAR);
ed.setTime(endDate);
int day2 = ed.get(Calendar.DAY_OF_YEAR);
sd = null;
ed = null;
...
intgetBetweenDays(String strFromDate, String strToDate)
get Between Days
try {
    Calendar clFrom = new GregorianCalendar();
    int iYear = Integer.parseInt(strFromDate.substring(0, 4));
    int iMonth = Integer.parseInt(strFromDate.substring(4, 6));
    int iDay = Integer.parseInt(strFromDate.substring(6, 8));
    clFrom.set(iYear, iMonth, iDay, 0, 0, 0);
    Calendar clTo = new GregorianCalendar();
    iYear = Integer.parseInt(strToDate.substring(0, 4));
...
GregorianCalendargetCalender(Date date)
get Calender
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
cal.set(Calendar.MILLISECOND, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.HOUR_OF_DAY, 0);
return cal;
DategetCertificateEndDate(int days)
get Certificate End Date
Calendar expiryTime = Calendar.getInstance();
expiryTime.add(Calendar.DAY_OF_YEAR, days);
return expiryTime.getTime();