Here you can find the source of getDaysByYearMonth(int year, int month)
public static int getDaysByYearMonth(int year, int month)
//package com.java2s; //License from project: Apache License import java.util.Calendar; public class Main { public static int getDaysByYearMonth(int year, int month) { Calendar a = Calendar.getInstance(); a.set(Calendar.YEAR, year); a.set(Calendar.MONTH, month - 1); a.set(Calendar.DATE, 1);//w ww. j a va 2 s . co m a.roll(Calendar.DATE, -1); int maxDate = a.get(Calendar.DATE); return maxDate; } }