Java Day getLastDay(Date date)

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

Description

get Last Day

License

Open Source License

Declaration

static public Date getLastDay(Date date) 

Method Source Code

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

import java.text.ParseException;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Main {
    /**/*from  ww  w. j  a  v  a  2 s.  c om*/
     * format pattern : yyyy-MM-dd
     */
    public static final SimpleDateFormat FORMAT_YYYY_MM_DD = new SimpleDateFormat("yyyy-MM-dd");

    static public Date getLastDay(String year, String month) throws ParseException {
        Date date = FORMAT_YYYY_MM_DD.parse(year + "-" + month + "-1");

        Calendar scalendar = new GregorianCalendar();
        scalendar.setTime(date);
        scalendar.add(Calendar.MONTH, 1);
        scalendar.add(Calendar.DATE, -1);
        date = scalendar.getTime();
        return date;
    }

    static public Date getLastDay(int year, int month) throws ParseException {
        Date date = FORMAT_YYYY_MM_DD.parse(year + "-" + month + "-1");

        Calendar scalendar = new GregorianCalendar();
        scalendar.setTime(date);
        scalendar.add(Calendar.MONTH, 1);
        scalendar.add(Calendar.DATE, -1);
        date = scalendar.getTime();
        return date;
    }

    static public Date getLastDay(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.set(Calendar.DAY_OF_MONTH, 1);
        c.roll(Calendar.DATE, false);
        return c.getTime();
    }
}

Related

  1. getDayStr(int i, String formatStr)
  2. getDayStringOfDate(Date date)
  3. getDayText(Date day)
  4. getDayTime_End()
  5. getLastDay()
  6. getLastDay(Date date)
  7. getLastDay(Date date)
  8. getLastDay(String nowdate, String inFormat, String outFormat)
  9. getLastDayOfQuarter(Date date)