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

StringgetFirstDayOfMonth(Calendar cal)
get First Day Of Month
return cal.get(Calendar.YEAR) + (cal.get(Calendar.MONTH) + 1) + "01";
DategetFirstDayOfMonth(final Calendar calendar, final Date date)
Get the first day of the input date's month
calendar.setTime(date);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
calendar.set(Calendar.DAY_OF_MONTH, 1);
Date firstDayInMonth = calendar.getTime();
return firstDayInMonth;
...
intgetLastDateOfMonth(Calendar calendar)
Returns the last date of the month represented by the passed cal
Calendar tmpCal = new GregorianCalendar(calendar.getTimeZone());
tmpCal.set(Calendar.YEAR, calendar.get(Calendar.YEAR));
tmpCal.set(Calendar.MONTH, calendar.get(Calendar.MONTH));
tmpCal.set(Calendar.DAY_OF_MONTH, 1);
return tmpCal.getActualMaximum(Calendar.DAY_OF_MONTH);
CalendargetLastDayOfMonth(Calendar c)
Gets the last day of the month based on the given Calendar .
Calendar result = (Calendar) c.clone();
result.set(Calendar.DAY_OF_MONTH, 31);
result.set(Calendar.HOUR_OF_DAY, 0);
result.set(Calendar.MINUTE, 0);
result.set(Calendar.SECOND, 0);
result.set(Calendar.MILLISECOND, 0);
return result;
DategetLastDayOfMonth(Calendar c)
get Last Day Of Month
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH) + 1;
int day = 1;
if (month > 11) {
    month = 0;
    year = year + 1;
c.set(year, month, day - 1, 0, 0, 0);
...
CalendargetLastDayOfMonth(Calendar calendar)
get Last Day Of Month
Calendar ret = (Calendar) calendar.clone();
ret.add(Calendar.MONTH, 1);
ret.set(Calendar.DAY_OF_MONTH, 0);
return ret;
intgetLastMonthDays(Calendar c)
get Last Month Days
Calendar calendar = c;
calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1);
return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
StringgetMonth(Calendar c)
gets the 3 character month string from the given calendar
return MONTHS[c.get(Calendar.MONTH)];
StringgetMonth(Calendar cal)
get Month
return strLen(String.valueOf(cal.get(Calendar.MONTH) + 1), 2);
intgetMonth(Calendar calendar)
get Month
return calendar.get(Calendar.MONTH);