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

voidsetStartTimeOfDay(Calendar calender)
set Start Time Of Day
calender.set(Calendar.HOUR_OF_DAY, calender.getActualMinimum(Calendar.HOUR_OF_DAY));
calender.set(Calendar.MINUTE, calender.getActualMinimum(Calendar.MINUTE));
calender.set(Calendar.SECOND, calender.getActualMinimum(Calendar.SECOND));
calender.set(Calendar.MILLISECOND, calender.getActualMinimum(Calendar.MILLISECOND));
CalendarsetToBeginningOfDay(Calendar cal)
This method will set the calenders hour/min/sec//milliseconds all to 0.
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
cal.getTimeInMillis();
return (cal);
voidsetToStartOfDay(Calendar start)
set To Start Of Day
start.set(GregorianCalendar.HOUR_OF_DAY, 0);
start.set(GregorianCalendar.MINUTE, 0);
voidsetToStartTimeOfTheDay(Calendar c)
set To Start Time Of The Day
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
voidstartOfDay(Calendar calendar)
Adjust the given calendar to the first millisecond of the current day.
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MILLISECOND, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MINUTE, 0);
longtoCountWorkDays(GregorianCalendar start, GregorianCalendar end)
to Count Work Days
long result = 0;
GregorianCalendar startDate = new GregorianCalendar();
GregorianCalendar endDate = new GregorianCalendar();
startDate.setTime(start.getTime());
endDate.setTime(end.getTime());
if ((startDate.get(GregorianCalendar.DAY_OF_WEEK) % 7) <= 1) {
    startDate.add(GregorianCalendar.DATE, 2 - (startDate.get(GregorianCalendar.DAY_OF_WEEK) % 7));
if ((endDate.get(GregorianCalendar.DAY_OF_WEEK) % 7) <= 1) {
    endDate.add(GregorianCalendar.DATE, -1 - (endDate.get(GregorianCalendar.DAY_OF_WEEK) % 7));
long totaldays = toDayInterval(startDate, endDate);
int s = endDate.get(GregorianCalendar.DAY_OF_WEEK) - startDate.get(GregorianCalendar.DAY_OF_WEEK);
if (s < 0) {
    s += 5;
if (totaldays % 7 != 0)
    result = s + (totaldays / 7) * 5 + 1;
else
    result = (totaldays / 7) * 5;
if (result < 0) {
    result = 0;
return result;
CalendartodayCalendar()
today Calendar
Calendar cal = new GregorianCalendar();
clearTime(cal);
return cal;
CalendartoEndOfDayCalendar(Date date)
to End Of Day Calendar
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.HOUR_OF_DAY, 23);
cal.set(Calendar.MINUTE, 59);
cal.set(Calendar.SECOND, 59);
return cal;
voidtoNextWorkDay(Calendar cal)
to Next Work Day
if (isRestDay(cal)) {
    cal.add(Calendar.DATE, 1);
    toNextWorkDay(cal);
CalendartrimToDay(Calendar calendar)
Trims the specified calendar to the day by resetting the following attributes:
  • hour of day
  • minutes
  • seconds
  • milliseconds
The passed calendar is not modified by this method.
Calendar cloneCal = (Calendar) calendar.clone();
cloneCal.set(Calendar.HOUR_OF_DAY, 0);
cloneCal.set(Calendar.MINUTE, 0);
cloneCal.set(Calendar.SECOND, 0);
cloneCal.set(Calendar.MILLISECOND, 0);
return cloneCal;