Here you can find the source of getLastDayOfMonth(int year, int month)
public static Integer getLastDayOfMonth(int year, int month)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; public class Main { public static Integer getLastDayOfMonth(int year, int month) { return intDateSub(getIntDate(newCalendar(year, month + 1, 1)), 1); }/*from w w w . j a v a 2 s.co m*/ public static Integer intDateSub(int date, int days) { return intDateAdd(date, -days); } public static Integer getIntDate(int year, int month, int day) { return getIntDate(newCalendar(year, month, day)); } public static Integer getIntDate(Calendar c) { int year = c.get(Calendar.YEAR); int month = c.get(Calendar.MONTH) + 1; int day = c.get(Calendar.DAY_OF_MONTH); return year * 10000 + month * 100 + day; } public static Integer getIntDate(Date d) { if (d == null) { return null; } Calendar c = Calendar.getInstance(); c.setTime(d); return getIntDate(c); } public static Calendar newCalendar(int year, int month, int day) { Calendar ret = Calendar.getInstance(); if (year < 100) { year = 2000 + year; } ret.set(year, month - 1, day); return ret; } public static Calendar newCalendar(int date) { int year = date / 10000; int month = (date % 10000) / 100; int day = date % 100; Calendar ret = Calendar.getInstance(); ret.set(year, month - 1, day); return ret; } public static Integer intDateAdd(int date, int days) { int year = date / 10000; int month = (date % 10000) / 100; int day = date % 100; day += days; return getIntDate(year, month, day); } }