Java Month of Year getPreYearMonth()

Here you can find the source of getPreYearMonth()

Description

get Pre Year Month

License

Apache License

Declaration

public static String getPreYearMonth() 

Method Source Code

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

import java.util.Calendar;

public class Main {

    public static String getPreYearMonth() {
        int year = getCurrentYear();
        int month = getCurrentMonth() - 1;
        String yearMonth = "";
        if (month == 1) {
            year = year - 1;/*from   w  w  w  .j a  va  2s. c  om*/
            month = 12;
        }
        if (month >= 10) {
            yearMonth = String.valueOf(year) + String.valueOf(month);
        } else {
            yearMonth = String.valueOf(year) + "0" + String.valueOf(month);
        }
        return yearMonth;
    }

    public static int getCurrentYear() {
        Calendar cal = Calendar.getInstance();
        // return cal.getTime().getYear()+1900;
        return cal.get(Calendar.YEAR);

    }

    public static int getCurrentMonth() {
        Calendar cal = Calendar.getInstance();
        return cal.get(Calendar.MONTH) + 1;
    }
}

Related

  1. getNumberOfDays(int year, int month)
  2. getOntologyURIBase(String defaultBase, boolean appendYear, boolean appendMonth, boolean appendDay)
  3. getPreviousDateStringByMonth(int months)
  4. getPreviousDay(int year, int month, int day, int days)
  5. getPrevMonth(String divisionDate, int day, String outputFormat)
  6. getSecondsOfMonth(int year, int month)
  7. getStartAndEndOfMonth(int month, int year)
  8. getStrDayOfWeek(int _year, int _month, int _day)
  9. getThisMonth(int year, int monthIndex)