Here you can find the source of perMonthDays(Calendar cal)
public static int perMonthDays(Calendar cal)
//package com.java2s; import java.util.Calendar; public class Main { public static int perMonthDays(Calendar cal) { int maxDays = 0; int month = cal.get(Calendar.MONTH); switch (month) { case Calendar.JANUARY: case Calendar.MARCH: case Calendar.MAY: case Calendar.JULY: case Calendar.AUGUST: case Calendar.OCTOBER: case Calendar.DECEMBER: maxDays = 31;/*w ww .java2s . com*/ break; case Calendar.APRIL: case Calendar.JUNE: case Calendar.SEPTEMBER: case Calendar.NOVEMBER: maxDays = 30; break; case Calendar.FEBRUARY: if (isLeap(cal.get(Calendar.YEAR))) { maxDays = 29; } else { maxDays = 28; } break; } return maxDays; } public static boolean isLeap(int year) { boolean leap = false; if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) { leap = true; } return leap; } }