Here you can find the source of getLastMonth()
public static String getLastMonth()
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.GregorianCalendar; public class Main { public static String getLastMonth() { GregorianCalendar now = new GregorianCalendar(); now.add(2, -1);// w ww . j a v a 2 s . c o m return format(now.getTime(), "yyyyMM"); } public static String format(java.util.Date date) { return date == null ? "" : format(date, "yyyy-MM-dd"); } public static String format(java.util.Date date, String pattern) { return date == null ? "" : new SimpleDateFormat(pattern).format(date); } }