Here you can find the source of endOfMonth(Date date)
Parameter | Description |
---|---|
date | a parameter |
public static Date endOfMonth(Date date)
//package com.java2s; //License from project: Open Source License 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 * Returns the final day of the given month of the given year. Takes month * and year parameters as integers. * * @param month * @param year * @return */ public static Date endOfMonth(int month, int year) { Calendar cal = new GregorianCalendar(); cal.set(year, month - 1, 1); int maxDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH); cal.set(Calendar.DAY_OF_MONTH, maxDay); return cal.getTime(); } /** * Returns the final day of the given month of the given year. Takes date * object as parameter. * * @param date * @return */ public static Date endOfMonth(Date date) { Calendar cal = new GregorianCalendar(); cal.setTime(date); int maxDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH); cal.set(Calendar.DAY_OF_MONTH, maxDay); return cal.getTime(); } }