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