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

CalendargetMonthBegin(Calendar c)
get Month Begin
Calendar r = getCurCalendar();
r.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), 1, 0, 0, 0);
return (r);
DategetMonthBegin(Calendar calendar)
get Month Begin
if (calendar == null) {
    return null;
Calendar date = new GregorianCalendar(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
        calendar.get(Calendar.DAY_OF_MONTH));
int dm = date.get(Calendar.DAY_OF_MONTH);
while (dm != 1) {
    date.add(Calendar.DATE, -1);
...
StringgetMonthName(Calendar cal)
get Month Name
String month = monthName[cal.get(Calendar.MONTH)];
return month;
DategetMonthStart(Calendar c)
get Month Start
c.set(Calendar.DAY_OF_MONTH, 1);
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
return c.getTime();
DategetMonthStart(Calendar cal)
get Month Start
cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.getActualMinimum(Calendar.DAY_OF_MONTH), 0, 0,
        1);
return cal.getTime();
StringgetMonthStr(Calendar cal)
get Month Str
int month = cal.get(Calendar.MONTH) + 1;
return month > 9 ? "" + month : "0" + month;
CalendargetNextMonth(Calendar calendar, int month)
get Next Month
calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) + month);
return calendar;
intgetNumDaysInMonth(GregorianCalendar aCalendar)
Gets the number of days in the current month.
int month = aCalendar.get(Calendar.MONTH);
int monthDays = mDaysInMonth[month];
if (month == Calendar.FEBRUARY && aCalendar.isLeapYear(aCalendar.get(Calendar.YEAR))) {
    ++monthDays;
return monthDays;
DategetStartOfMonth(Date day, Calendar cal)
get Start Of Month
if (day == null)
    day = new Date();
cal.setTime(day);
cal.set(Calendar.HOUR_OF_DAY, cal.getMinimum(Calendar.HOUR_OF_DAY));
cal.set(Calendar.MINUTE, cal.getMinimum(Calendar.MINUTE));
cal.set(Calendar.SECOND, cal.getMinimum(Calendar.SECOND));
cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND));
cal.set(Calendar.DAY_OF_MONTH, 1);
...
voidincrementMonth(Calendar cal)
Increments month of Calendar by one month.
Calendar cal2 = (Calendar) cal.clone();
floorDayOfMonth(cal2);
cal2.add(Calendar.MONTH, 1);
if (cal.get(Calendar.DAY_OF_MONTH) > cal2.getActualMaximum(Calendar.DAY_OF_MONTH)) {
    floorDayOfMonth(cal);
    cal.add(Calendar.MONTH, 2);
cal.add(Calendar.MONTH, 1);
...