Here you can find the source of getLastMonthDay()
public static Date getLastMonthDay()
//package com.java2s; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static Date getLastMonthDay() { String pattern = "yyyy-MM-dd"; Calendar cd = Calendar.getInstance(); cd.add(Calendar.MONTH, -1); String newTime = String.valueOf(cd.get(Calendar.YEAR)) + "-" + String.valueOf(cd.get(Calendar.MONTH) + 1) + "-" + String.valueOf("01"); return convertStringToDate(newTime, pattern); }//from w w w . j ava 2 s . co m public static Date convertStringToDate(String dateStr, String pattern) { SimpleDateFormat format = new SimpleDateFormat(pattern); try { return format.parse(dateStr); } catch (ParseException e) { e.printStackTrace(); return null; } } }