Java Day of Month getLastDayOfMonth(Date date)

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

Description

get Last Day Of Month

License

Apache License

Declaration


public static Date getLastDayOfMonth(Date date) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    private static final int DEFAULT_SECOND = 59;
    private static final int DEFAULT_MINUTE = 59;
    private static final int DEFALUT_HOUR_OF_DAY = 23;

    public static Date getLastDayOfMonth(Date date) {
        Calendar calendar = Calendar.getInstance();
        Date tempDate = (date == null ? new Date() : date);
        calendar.setTime(tempDate);/*ww w.  j av  a 2s  . com*/
        calendar.set(Calendar.DATE, getMaxDayNum(tempDate));
        calendar.set(Calendar.HOUR_OF_DAY, DEFALUT_HOUR_OF_DAY);
        calendar.set(Calendar.MINUTE, DEFAULT_MINUTE);
        calendar.set(Calendar.SECOND, DEFAULT_SECOND);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    public static int getMaxDayNum(Date currentDate) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(currentDate);
        return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);

    }
}

Related

  1. getLastdayofMonth()
  2. getlastDayOfMonth()
  3. getLastDayOfMonth()
  4. getLastDayOfMonth(Calendar c)
  5. getLastDayOfMonth(Date currDate)
  6. getLastDayOfMonth(Date date)
  7. getLastDayOfMonth(Date date)
  8. getLastDayOfMonth(Date date)
  9. getLastDayOfMonth(Date date)