Here you can find the source of getMonthEnd(Date date)
public static Date getMonthEnd(Date date)
//package com.java2s; import java.text.ParsePosition; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Main { public static Date getMonthEnd(Date date) { int year = Integer.parseInt(FormatDate(date, "yyyy")); int month = Integer.parseInt(FormatDate(date, "MM")); int day = Integer.parseInt(FormatDate(date, "dd")); GregorianCalendar calendar = new GregorianCalendar(year, month - 1, day, 0, 0, 0); int monthLength = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); String newDateStr = FormatDate(date, "yyyy") + "-" + FormatDate(date, "MM") + "-"; if (monthLength < 10) newDateStr += "0" + monthLength; else/* w ww.j av a2 s .c o m*/ newDateStr += "" + monthLength; return stringToDateShort(newDateStr); } public static String FormatDate(Date date, String sf) { if (date == null) return ""; SimpleDateFormat dateformat = new SimpleDateFormat(sf); return dateformat.format(date); } public static Date stringToDateShort(String dateString) { String sf = "yyyy-MM-dd"; Date dt = stringToDate(dateString, sf); return dt; } public static Date stringToDate(String dateString) { String sf = "yyyy-MM-dd HH:mm:ss"; Date dt = stringToDate(dateString, sf); return dt; } public static Date stringToDate(String dateString, String sf) { ParsePosition pos = new ParsePosition(0); SimpleDateFormat sdf = new SimpleDateFormat(sf); Date dt = sdf.parse(dateString, pos); return dt; } }