Here you can find the source of getDaysOfMonth(String year, String month)
public static int getDaysOfMonth(String year, String month)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { public static int getDaysOfMonth(String year, String month) { int days = 0; if (month.equals("1") || month.equals("3") || month.equals("5") || month.equals("7") || month.equals("8") || month.equals("10") || month.equals("12")) { days = 31;// w w w . j a va2s. c om } else if (month.equals("4") || month.equals("6") || month.equals("9") || month.equals("11")) { days = 30; } else { if ((Integer.parseInt(year) % 4 == 0 && Integer.parseInt(year) % 100 != 0) || Integer.parseInt(year) % 400 == 0) { days = 29; } else { days = 28; } } return days; } public static int getDaysOfMonth(int year, int month) { Calendar calendar = Calendar.getInstance(); calendar.set(year, month - 1, 1); return calendar.getActualMaximum(Calendar.DAY_OF_MONTH); } }