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

voidmoveToCalendarDay(Calendar cal, int day)
move To Calendar Day
assertArgumentNotMinusNotZeroInteger("day", day);
cal.set(Calendar.DAY_OF_MONTH, day);
voidmoveToCalendarDayJust(Calendar cal)
move To Calendar Day Just
moveToCalendarDayJust(cal, cal.getActualMinimum(Calendar.HOUR_OF_DAY));
CalendarnewCalendarForDay(Date date)
new Calendar For Day
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.HOUR, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal;
voidresetToBeginningOfDay(Calendar c)
reset 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, 0);
booleansameDay(Calendar a, Calendar b)
same Day
return a.get(Calendar.DAY_OF_YEAR) == b.get(Calendar.DAY_OF_YEAR)
        && a.get(Calendar.MONTH) == b.get(Calendar.MONTH) && a.get(Calendar.YEAR) == b.get(Calendar.YEAR);
booleansameDay(Calendar c1, Calendar c2)
same Day
return c1.get(Calendar.YEAR) == c2.get(Calendar.YEAR)
        && c1.get(Calendar.DAY_OF_YEAR) == c2.get(Calendar.DAY_OF_YEAR);
booleansameDay(Calendar one, Calendar two)
Returns true if the two given calendars are dated on the same year, month and day.
return one.get(Calendar.DATE) == two.get(Calendar.DATE) && sameMonth(one, two);
voidsetDayToCalendar(int days, Calendar calendar)
Converts the number of elapsed days from 0001/01/01 (YYYY/MM/DD) to the corresponded date, and set it to the target calendar object.
int year = getYearFromDay(days);
int daysInYear = days - getDayFromYear(year);
boolean leap = isLeap(year);
int month = getMonthOfYear(daysInYear, leap);
int day = getDayOfMonth(daysInYear, leap);
calendar.set(year, month - 1, day, 0, 0, 0);
calendar.set(Calendar.MILLISECOND, 0);
CalendarsetEndDay(Calendar cal)
set End Day
cal.set(11, 23);
cal.set(12, 59);
cal.set(13, 59);
return cal;
voidsetStartOfDay(final Calendar calendar)
set Start Of Day
calendar.set(Calendar.HOUR, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);