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

CalendargetRelativeCalendar(int offsetDays)
Computes the day that has the given offset in days to today and returns it as an instance of Calendar .
Calendar today = new GregorianCalendar();
return getRelativeCalendar(today, offsetDays);
CalendargetSafeTimeForAllDay(Calendar cal)
Get a safe time for all day given a certain calendar.
if (TimeZone.getDefault().getRawOffset() > 0) {
    cal.set(Calendar.HOUR_OF_DAY, 14);
} else if (TimeZone.getDefault().getRawOffset() <= 0) {
    cal.set(Calendar.HOUR_OF_DAY, 1);
return cal;
Calendar[]getStartAndEndOfDay(Calendar calendar)
get Start And End Of Day
Calendar startDate = Calendar.getInstance();
startDate.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DATE), 0, 0);
Calendar endDate = Calendar.getInstance();
endDate.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DATE), 23, 59);
return new Calendar[] { startDate, endDate };
CalendargetStartOfDay(Calendar cal)
get Start Of Day
Calendar ret = Calendar.getInstance();
ret.setTime(cal.getTime());
ret.set(11, 0);
ret.set(12, 0);
ret.set(13, 0);
ret.set(14, 0);
return ret;
CalendargetThatMonday(Calendar cal)
get That Monday
int n = cal.get(Calendar.DAY_OF_WEEK) - Calendar.MONDAY;
cal.add(Calendar.DATE, n);
return cal;
CalendargetTodayCalendar()
Returns a Java calendar rounded to the current day
Calendar calendar = Calendar.getInstance(timeZone);
calendar.setTimeZone(timeZone);
calendar.set(Calendar.HOUR, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar;
intgetWorkingDay(Calendar beginDate, Calendar endDate)
get Working Day
int result = -1;
if (beginDate.after(endDate)) {
    Calendar swap = beginDate;
    beginDate = endDate;
    endDate = swap;
int charge_start_date = 0;
int charge_end_date = 0;
...
intgetWorkingDay(Calendar d1, Calendar d2)
get Working Day
int result = 0;
int betweendays = getDaysBetween(d1, d2);
int firstDayInWeek = d1.get(Calendar.DAY_OF_WEEK);
if (firstDayInWeek > 1) {
    result = 7 - firstDayInWeek;
    betweendays -= (result + 1);
result += betweendays / 7 * 5;
...
voidincrementDay(Calendar cal)
increment Day
cal.add(Calendar.DAY_OF_MONTH, 1);
voidincrementOneDay(Calendar calendar)
increment One Day
int monthBeforeIncrement = calendar.get(Calendar.MONTH);
calendar.add(Calendar.DAY_OF_YEAR, 1);
int monthAfterIncrement = calendar.get(Calendar.MONTH);
if (monthBeforeIncrement == Calendar.DECEMBER && monthAfterIncrement == Calendar.JANUARY) {
    calendar.setMinimalDaysInFirstWeek(calculateMinimalDaysInFirstWeek(calendar));