Here you can find the source of getMonthBefore(Date d, int number)
public static String getMonthBefore(Date d, int number)
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static String getMonthBefore(Date d, int number) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); calendar.add(Calendar.MONTH, number); calendar.add(Calendar.DAY_OF_MONTH, -1); return formatter.format(calendar.getTime()); }// ww w . j a va 2 s . c o m }