Java Month Day getMonthLastDay(String dateString)

Here you can find the source of getMonthLastDay(String dateString)

Description

return the last day of the date's month of specified string value in format: yyyy-MM

License

Apache License

Parameter

Parameter Description
dateString String value of date

Return

Date value

Declaration

public static Date getMonthLastDay(String dateString) 

Method Source Code

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

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

public class Main {
    /**/*from   w w w  . j ava 2s. c om*/
     * return the last day of the date's month of specified string value in format: yyyy-MM
     *
     * @param dateString String value of date
     * @return Date value
     */
    public static Date getMonthLastDay(String dateString) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
        Date date = null;
        try {
            date = simpleDateFormat.parse(dateString);
        } catch (Exception e) {
            e.printStackTrace();
        }
        Calendar calendar = Calendar.getInstance();
        if (date != null) {
            calendar.setTime(date);
        }
        calendar.add(Calendar.MONTH, 1);
        calendar.add(Calendar.DATE, -1);
        return calendar.getTime();
    }
}

Related

  1. getMonthFristWeekSunday(String month)
  2. getMonthLastDay()
  3. getMonthLastDay()
  4. getMonthLastDay()
  5. getMonthLastDay(String curmonth, int month)
  6. getMonthLastDay(String fmt)
  7. getMonthMaxDay(String sDate)
  8. getMonthWeek(String curday)
  9. getMonthWeek(String curday)