Java Utililty Methods Calendar Month

List of utility methods to do Calendar Month

Description

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

Method

CalendarincrementMonthByVal(Calendar theCal, int val)
increment Month By Val
Calendar incrementedCalendar = (Calendar) theCal.clone();
int currentDay = incrementedCalendar.get(Calendar.DAY_OF_MONTH);
incrementedCalendar.add(Calendar.MONTH, val);
incrementedCalendar.set(Calendar.DAY_OF_MONTH, currentDay);
int newDay = incrementedCalendar.get(Calendar.DAY_OF_MONTH);
if (newDay < currentDay) { 
    incrementedCalendar.roll(Calendar.DAY_OF_MONTH, false);
    int rolledBackDay = incrementedCalendar.get(Calendar.DAY_OF_MONTH);
...
intintToCalendarMonth(int month)
int To Calendar Month
if (month == 1) {
    return Calendar.JANUARY;
} else if (month == 2) {
    return Calendar.FEBRUARY;
} else if (month == 3) {
    return Calendar.MARCH;
} else if (month == 4) {
    return Calendar.APRIL;
...
booleanisFirstDayOfMonth(Calendar calendar)
is First Day Of Month
if (calendar.get(Calendar.DAY_OF_MONTH) == 1) {
    return true;
return false;
intlastDayOfMonth(Calendar c)
last Day Of Month
return c.getActualMaximum(Calendar.DATE);
intmonth(Calendar calendar)
month
return calendar.get(Calendar.MONTH) + 1;
intmonth(Calendar date)
month
return date.get(Calendar.MONTH) + 1;
intnumberOfDaysInMonth(Calendar cal)
number Of Days In Month
cal.set(Calendar.DAY_OF_MONTH, 1);
cal.set(Calendar.HOUR, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
cal.add(Calendar.MONTH, 1);
cal.add(Calendar.DAY_OF_MONTH, -1);
return cal.get(Calendar.DAY_OF_MONTH);
...
booleansameMonth(Calendar one, Calendar two)
Returns true if the two given calendars are dated on the same year and month.
return one.get(Calendar.MONTH) == two.get(Calendar.MONTH) && sameYear(one, two);
voidsetDate(Calendar cal, int month, int date)
set Date
cal.clear();
cal.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR));
cal.set(Calendar.MONTH, month);
cal.set(Calendar.DATE, date);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
...
voidsetDate(Calendar cal, int month, int date, boolean endOfDay)
set Date
cal.clear();
cal.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR));
cal.set(Calendar.MONTH, month);
cal.set(Calendar.DATE, date);
if (endOfDay) {
    cal.set(Calendar.HOUR_OF_DAY, 23);
    cal.set(Calendar.MINUTE, 59);
    cal.set(Calendar.SECOND, 59);
...