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

intcalendarMonthToInt(int calendarMonth)
calendar Month To Int
if (calendarMonth == Calendar.JANUARY) {
    return 1;
} else if (calendarMonth == Calendar.FEBRUARY) {
    return 2;
} else if (calendarMonth == Calendar.MARCH) {
    return 3;
} else if (calendarMonth == Calendar.APRIL) {
    return 4;
...
voidcalToLastDayOfMonth(Calendar c)
cal To Last Day Of Month
int day = lastDayOfMonth(c);
c.set(Calendar.DATE, day);
CalendarconvertRemoveAfterMonth(Calendar cal)
convert Remove After Month
Calendar outCal = Calendar.getInstance();
outCal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), 1, 0, 0, 0);
return outCal;
voidendOfMonth(Calendar calendar)
Adjusts the calendar to the end of the current month.
calendar.add(Calendar.MONTH, 1);
startOfMonth(calendar);
calendar.add(Calendar.MILLISECOND, -1);
voidfloorDayOfMonth(Calendar cal)
floor Day Of Month
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
intgetCalDayofMonth(Date calendarDay)
This method is used for getting calendar date of month
Calendar calendar = Calendar.getInstance();
calendar.setTime(calendarDay);
return calendar.get(Calendar.DAY_OF_MONTH);
StringgetDayOfMonthPostfix(Calendar cal)
get Day Of Month Postfix
String postfix = "th";
switch (cal.get(Calendar.DAY_OF_MONTH)) {
case 1:
case 21:
case 31:
    postfix = "st";
    break;
case 2:
...
intgetDaysInMonth(Calendar cal)
get Days In Month
return getDaysInMonth(cal.get(Calendar.MONTH), cal.get(Calendar.YEAR));
DategetFirstDateOfMonth(Calendar calendar)
get First Date Of Month
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
return calendar.getTime();
DategetFirstDayOfMonth(Calendar c)
get First Day Of Month
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = 1;
c.set(year, month, day, 0, 0, 0);
return c.getTime();