Java Utililty Methods Month of Year

List of utility methods to do Month of Year

Description

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

Method

intdaysInMonth(int month, int year)
Returns the number of days in the month given for a given year.
if (month == Calendar.APRIL || month == Calendar.JUNE || month == Calendar.SEPTEMBER
        || month == Calendar.NOVEMBER) {
    return 30;
} else if (month == Calendar.FEBRUARY) {
    return 28 + (isLeap(year) ? 1 : 0);
} else {
    return 31;
intdaysInMonth(int month, int year)
days In Month
cd.set(year, month - 1, 1);
return cd.getActualMaximum(Calendar.DAY_OF_MONTH);
intdaysInMonth(int year, int month)
days In Month
java.util.Calendar cal = new java.util.GregorianCalendar(year, month - 1, 1);
return cal.getActualMaximum(java.util.Calendar.DAY_OF_MONTH);
intdaysInMonth(int year, int month)
days In Month
Calendar mycal = new GregorianCalendar(year, month - 1, 1);
return mycal.getActualMaximum(Calendar.DAY_OF_MONTH);
int[]get_NextSunday_YearMonthDay_integerArray()
ge Next Sunda Year Month Dainteger Array
Date objDateLocal = new Date();
Calendar objCalendarLocal = Calendar.getInstance();
int nLocal_DD = 0;
int nLocal_MM = 0;
objCalendarLocal.setTime(objDateLocal);
nLocal_DD = objCalendarLocal.get(Calendar.DATE);
nLocal_MM = objCalendarLocal.get(Calendar.MONTH);
int nLocal_MaxDayCount = objCalendarLocal.getActualMaximum(Calendar.DAY_OF_MONTH);
...
StringgetActualMonthBefore(int year, int month, int i)
get Actual Month Before
SimpleDateFormat daytime = new SimpleDateFormat("yyyyMM");
Calendar calendar = Calendar.getInstance();
calendar.set(year, month, 1);
calendar.set(Calendar.MONTH, calendar.get(Calendar.MONDAY) - (i + 1));
return daytime.format(calendar.getTime());
CalendargetCalforMonth(String month, String year)
get Calfor Month
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MONTH, Integer.parseInt(month));
cal.set(Calendar.YEAR, Integer.parseInt(year));
cal.set(Calendar.DATE, 1);
if (cal.get(Calendar.DAY_OF_WEEK) > 1)
    cal.add(Calendar.DATE, -cal.get(Calendar.DAY_OF_WEEK));
else
    cal.add(Calendar.DATE, -8);
...
intgetDaysByYearMonth(int year, int month)
get Days By Year Month
Calendar a = Calendar.getInstance();
a.set(Calendar.YEAR, year);
a.set(Calendar.MONTH, month - 1);
a.set(Calendar.DATE, 1);
a.roll(Calendar.DATE, -1);
int maxDate = a.get(Calendar.DATE);
return maxDate;
intgetDefaultHolidays(int year, int month)
get Default Holidays
GregorianCalendar cal = new GregorianCalendar(year, month - 1, 1);
int x = 0;
for (int d = 0;; d++) {
    int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
    if (dayOfWeek == Calendar.SUNDAY || dayOfWeek == Calendar.SATURDAY)
        x |= (1 << d);
    cal.add(Calendar.DAY_OF_YEAR, 1);
    if (cal.get(Calendar.MONTH) + 1 != month)
...
StringgetEndOfMonth(String year, String month)
get End Of Month
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, Integer.parseInt(year));
cal.set(Calendar.MONTH, Integer.parseInt(month) - 1);
return cal.getActualMaximum(Calendar.DAY_OF_MONTH) + "";