Android Month String Get getLastMonthStr()

Here you can find the source of getLastMonthStr()

Description

get Last Month Str

Declaration

public static String getLastMonthStr() 

Method Source Code

//package com.java2s;

import java.util.Calendar;

public class Main {
    public static String getLastMonthStr() {
        Calendar cal = Calendar.getInstance();
        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH) + 1;
        if (--month == 0) {
            month = 12;/*w  w w  .  jav a  2s. co m*/
            year--;
        }
        return getDate(year, month);
    }

    public static String getDate(int year, int month) {
        String date = null;
        String a = String.valueOf(year);
        String b = String.valueOf(month);
        if (month > 9) {
            date = a + b;
        } else {
            date = a + "0" + b;
        }
        return date;
    }
}

Related

  1. getCurMonthStr()
  2. getMonthBefore(String format)
  3. getMonthString(int month, int abbrev)
  4. getMonthStringByIndex(int index)
  5. getReadableMonth(int month)