Java Day of Month getLastDayOfMonth(Date date)

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

Description

get Last Day Of Month

License

Open Source License

Declaration

public static Date getLastDayOfMonth(Date date) throws ParseException 

Method Source Code


//package com.java2s;
import java.text.ParseException;

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

public class Main {

    public static Date getLastDayOfMonth(Date date) throws ParseException {

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);//  w  w w  .j a  v  a2s .  co  m
        calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), 1);
        calendar.roll(Calendar.DATE, -1);
        return calendar.getTime();
    }

    public static Date getLastDayOfMonth(Integer year, Integer month) {
        Calendar calendar = Calendar.getInstance();
        if (year == null) {
            year = calendar.get(Calendar.YEAR);
        }
        if (month == null) {
            month = calendar.get(Calendar.MONTH);
        }
        calendar.set(year, month, 1);
        calendar.roll(Calendar.DATE, -1);
        return calendar.getTime();
    }
}

Related

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