Here you can find the source of getLastMonthStr()
public static String getLastMonthStr()
//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; } }