Java Month Day getPreviosMonthFirstDay()

Here you can find the source of getPreviosMonthFirstDay()

Description

get Previos Month First Day

License

Open Source License

Declaration

public static String getPreviosMonthFirstDay() 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;

public class Main {

    public static String getPreviosMonthFirstDay() {
        String curYearMonth = getDateTime6String();
        String yearMonth = getPreviousYearMonth(curYearMonth);
        return yearMonth.substring(0, 4) + "-" + yearMonth.substring(4) + "-01";
    }/*from  w  ww. j a va 2  s .  co  m*/

    public static String getDateTime6String() {
        return new SimpleDateFormat("yyyyMM").format(nowDate());
    }

    public static String getPreviousYearMonth(String currentYearMonth) {
        int year = Integer.parseInt(currentYearMonth.substring(0, 4));
        int month = Integer.parseInt(currentYearMonth.substring(4));
        if (month == 1) {
            year -= 1;
            month = 12;
        } else {
            month -= 1;
        }

        StringBuffer strb = new StringBuffer().append(year);
        if (month > 9)
            strb.append(month);
        else
            strb.append("0").append(month);
        return strb.toString();
    }

    public static java.util.Date nowDate() {
        return new java.util.Date();
    }
}

Related

  1. getMonthLastDay(String dateString)
  2. getMonthLastDay(String fmt)
  3. getMonthMaxDay(String sDate)
  4. getMonthWeek(String curday)
  5. getMonthWeek(String curday)
  6. getShortFirstDayOfMonth()
  7. getStringOfFirstDayInMonth()
  8. getStringOfFirstDayInMonth()
  9. isFirstDayOfMonth()