Here you can find the source of getLastDayOfMonth(Date date)
public static Date getLastDayOfMonth(Date date) throws ParseException
//package com.java2s; import java.text.ParseException; import java.util.Calendar; import java.util.Date; public class Main { public static Date getLastDayOfMonth(Date date) throws ParseException { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);// w w w .j a v a2s . co m calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), 1); calendar.roll(Calendar.DATE, -1); return calendar.getTime(); } public static Date getLastDayOfMonth(Integer year, Integer month) { Calendar calendar = Calendar.getInstance(); if (year == null) { year = calendar.get(Calendar.YEAR); } if (month == null) { month = calendar.get(Calendar.MONTH); } calendar.set(year, month, 1); calendar.roll(Calendar.DATE, -1); return calendar.getTime(); } }