Here you can find the source of getLastDay(Date date)
static public Date getLastDay(Date date)
//package com.java2s; //License from project: Open Source License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Main { /**/*from ww w. j a v a 2 s. c om*/ * format pattern : yyyy-MM-dd */ public static final SimpleDateFormat FORMAT_YYYY_MM_DD = new SimpleDateFormat("yyyy-MM-dd"); static public Date getLastDay(String year, String month) throws ParseException { Date date = FORMAT_YYYY_MM_DD.parse(year + "-" + month + "-1"); Calendar scalendar = new GregorianCalendar(); scalendar.setTime(date); scalendar.add(Calendar.MONTH, 1); scalendar.add(Calendar.DATE, -1); date = scalendar.getTime(); return date; } static public Date getLastDay(int year, int month) throws ParseException { Date date = FORMAT_YYYY_MM_DD.parse(year + "-" + month + "-1"); Calendar scalendar = new GregorianCalendar(); scalendar.setTime(date); scalendar.add(Calendar.MONTH, 1); scalendar.add(Calendar.DATE, -1); date = scalendar.getTime(); return date; } static public Date getLastDay(Date date) { Calendar c = Calendar.getInstance(); c.setTime(date); c.set(Calendar.DAY_OF_MONTH, 1); c.roll(Calendar.DATE, false); return c.getTime(); } }