Java Month Day getLastMonthDay()

Here you can find the source of getLastMonthDay()

Description

get Last Month Day

License

Open Source License

Declaration

public static Date getLastMonthDay() 

Method Source Code


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

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

public class Main {

    public static Date getLastMonthDay() {
        String pattern = "yyyy-MM-dd";
        Calendar cd = Calendar.getInstance();
        cd.add(Calendar.MONTH, -1);
        String newTime = String.valueOf(cd.get(Calendar.YEAR)) + "-" + String.valueOf(cd.get(Calendar.MONTH) + 1)
                + "-" + String.valueOf("01");
        return convertStringToDate(newTime, pattern);
    }//from w w  w  .  j  ava  2 s . co m

    public static Date convertStringToDate(String dateStr, String pattern) {
        SimpleDateFormat format = new SimpleDateFormat(pattern);
        try {
            return format.parse(dateStr);
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }
}

Related

  1. getFirstDayOfMonth(Date date)
  2. getFirstDayOfMonth(Long date)
  3. getFirstDayOfNextMonth()
  4. getFirstDayStringOfMonth(Date date)
  5. getFirstDayStrOfMonth(Date date)
  6. getLastMonthLastDate()
  7. getLastMonthLastDay()
  8. getLastMonthLastDay()
  9. getLastMothStart()