Java Month End endOfMonth(Date date)

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

Description

end Of Month

License

Open Source License

Declaration

public static Date endOfMonth(Date date) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Calendar;
import java.util.Date;

public class Main {

    public static Date endOfMonth(Date date) {
        if (date == null) {
            return date;
        }/*ww  w  .j ava  2 s.c  o m*/
        Date start = newDate(date.getYear(), date.getMonth(), 1, 0, 0, 0);
        Calendar cal = Calendar.getInstance();
        cal.setTime(start);
        cal.add(Calendar.MONTH, 1);
        cal.add(Calendar.SECOND, -1);
        return cal.getTime();
    }

    /**
     *
     * @param year
     * @param month
     * @param day
     * @param hour
     * @param minute
     * @param sencond
     * @return
     */
    public static Date newDate(int year, int month, int day, int hour, int minute, int sencond) {
        if (month >= 1) {
            month = month - 1;
        }
        return new Date(year + 1900, month, day, hour, minute, sencond);
    }
}

Related

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