Java Month End getEndOfMonth(Date date)

Here you can find the source of getEndOfMonth(Date date)

Description

Gets the end of month.

License

Open Source License

Parameter

Parameter Description
date to get the end of month for

Return

last day of month.

Declaration

public static Date getEndOfMonth(Date date) 

Method Source Code


//package com.java2s;
import java.util.Calendar;
import java.util.Date;

public class Main {
    /**// ww w .  j  av  a  2 s .  c o  m
     * Gets the end of month.
     *
     * @param date to get the end of month for
     * @return last day of month.
     */
    public static Date getEndOfMonth(Date date) {

        if (null == date) {
            date = new Date();
        }

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        calendar.add(Calendar.MONTH, 1);
        calendar.add(Calendar.DATE, -1);

        return calendar.getTime();
    }
}

Related

  1. endOfMonth(Date date)
  2. endOfMonth(Date date)
  3. getEndOfMonth(Date dt)
  4. getEndOfMonth(long date)