Here you can find the source of getLastDayOfMonth(Date date)
public static Date getLastDayOfMonth(Date date)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; public class Main { private static final int DEFAULT_SECOND = 59; private static final int DEFAULT_MINUTE = 59; private static final int DEFALUT_HOUR_OF_DAY = 23; public static Date getLastDayOfMonth(Date date) { Calendar calendar = Calendar.getInstance(); Date tempDate = (date == null ? new Date() : date); calendar.setTime(tempDate);/*ww w. j av a 2s . com*/ calendar.set(Calendar.DATE, getMaxDayNum(tempDate)); calendar.set(Calendar.HOUR_OF_DAY, DEFALUT_HOUR_OF_DAY); calendar.set(Calendar.MINUTE, DEFAULT_MINUTE); calendar.set(Calendar.SECOND, DEFAULT_SECOND); calendar.set(Calendar.MILLISECOND, 0); return calendar.getTime(); } public static int getMaxDayNum(Date currentDate) { Calendar calendar = Calendar.getInstance(); calendar.setTime(currentDate); return calendar.getActualMaximum(Calendar.DAY_OF_MONTH); } }