Java tutorial
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static String getBeforeTime(int months, SimpleDateFormat format, Date now) { Calendar calendar = Calendar.getInstance(); calendar.setTime(now); calendar.add(calendar.MONTH, -months); return format.format(calendar.getTime()); } }