Here you can find the source of getLastdayOfMonth(int month, int year)
public static Calendar getLastdayOfMonth(int month, int year)
//package com.java2s; /*// w w w . ja v a2 s. c om * @ (#) CalendarUtils.java * * Copyright (c) 2010 ClickDiagnostics Inc. All Rights Reserved. This software is the * confidential and proprietary information of ClickDiagnostics ("Confidential * Information"). You shall not disclose such Confidential Information and shall * use it only in accordance with the terms of the license agreement you entered * into with ClickDiagnostics. */ import java.util.Calendar; public class Main { public static Calendar getLastdayOfMonth(int month, int year) { Calendar cal = Calendar.getInstance(); int days = 30; if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) { days = 31; } else if (month == 2) { // need to calculate leap year days = 28; } cal.set(Calendar.DAY_OF_MONTH, days); cal.set(Calendar.MONTH, month - 1); // In calendar, Month start from // 0 // Not in 1 cal.set(Calendar.YEAR, year); return cal; } }