Java Utililty Methods Calendar Day

List of utility methods to do Calendar Day

Description

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

Method

intabsoluteDay(Calendar cal)
Given a Calendar, return the number of days since 1600/12/31.
return cal.get(Calendar.DAY_OF_YEAR) + daysInPriorYears(cal.get(Calendar.YEAR));
intabsoluteDay(Calendar cal, boolean use1904windowing)
Given a Calendar, return the number of days since 1900/12/31.
final int minY = use1904windowing ? 1903 : 1899;
final int year = cal.get(Calendar.YEAR);
return year == minY ? 0
        : cal.get(Calendar.DAY_OF_YEAR) + daysInPriorYears(cal.get(Calendar.YEAR), use1904windowing);
booleanafterCurrentDay(Calendar time)
after Current Day
boolean afterCurrent = false;
Calendar currentTime = createCalendar(System.currentTimeMillis());
int yearOfTime = getYear(time);
int yearOfCurrentTime = getYear(currentTime);
if (yearOfTime > yearOfCurrentTime)
    afterCurrent = true;
else if (yearOfTime == yearOfCurrentTime && getDay(time) > getDay(currentTime))
    afterCurrent = true;
...
CalendarcalendarAtStartOfToday()
calendar At Start Of Today
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar;
intcalendarDayToOrdinalDay(int dow)
calendar Day To Ordinal Day
return dow == Calendar.MONDAY ? 1
        : dow == Calendar.TUESDAY ? 2
                : dow == Calendar.WEDNESDAY ? 3
                        : dow == Calendar.THURSDAY ? 4
                                : dow == Calendar.FRIDAY ? 5 : dow == Calendar.SATURDAY ? 6 : 7;
voidcalToBeginningOfDay(Calendar c)
cal To Beginning Of Day
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 000);
voidceilAllLessThanDay(Calendar cal)
ceil All Less Than Day
cal.set(Calendar.MILLISECOND, cal.getActualMaximum(Calendar.MILLISECOND));
cal.set(Calendar.SECOND, cal.getActualMaximum(Calendar.SECOND));
cal.set(Calendar.MINUTE, cal.getActualMaximum(Calendar.MINUTE));
cal.set(Calendar.HOUR_OF_DAY, cal.getActualMaximum(Calendar.HOUR_OF_DAY));
CalendarconvertEndOfDay(Calendar cal)
convert End Of Day
Calendar outCal = Calendar.getInstance();
outCal.setTimeInMillis(0);
outCal.set(Calendar.YEAR, cal.get(Calendar.YEAR));
outCal.set(Calendar.MONTH, cal.get(Calendar.MONTH));
outCal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH));
outCal.set(Calendar.HOUR, 23);
outCal.set(Calendar.MINUTE, 59);
outCal.set(Calendar.SECOND, 59);
...
voidcopyCalendarDay(final Calendar src, final Calendar dest)
copy Calendar Day
copyCalField(src, dest, Calendar.YEAR);
copyCalField(src, dest, Calendar.MONTH);
copyCalField(src, dest, Calendar.DAY_OF_MONTH);
dest.set(Calendar.HOUR_OF_DAY, 0);
dest.set(Calendar.MINUTE, 0);
dest.set(Calendar.SECOND, 0);
dest.set(Calendar.MILLISECOND, 0);
CalendarcreateBeginningOfDay(Calendar calendar)
create Beginning Of Day
Calendar c = (Calendar) calendar.clone();
c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DATE), 0, 0, 0);
c.set(Calendar.MILLISECOND, 0);
return c;