Here you can find the source of getLastDayOfMonth(Date dt)
Parameter | Description |
---|---|
Date | a parameter |
public static Date getLastDayOfMonth(Date dt)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; public class Main { /**/*ww w .j a v a 2s . c o m*/ * Get last day of month (2007-01-12 = 2007-01-31) * * @param Date * @return Date */ public static Date getLastDayOfMonth(Date dt) { if (null == dt) { return null; } Calendar calendar = Calendar.getInstance(); calendar.setTime(dt); int day = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); Calendar rtnCalendar = Calendar.getInstance(); rtnCalendar.clear(); rtnCalendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR)); rtnCalendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH)); rtnCalendar.set(Calendar.DAY_OF_MONTH, day); return rtnCalendar.getTime(); } }