Here you can find the source of getBeforeDate(Date date, int days)
public static String getBeforeDate(Date date, int days)
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static String getBeforeDate(Date date, int days) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Calendar calendar = Calendar.getInstance(); calendar.setTime(date);//from w ww .j a v a 2 s. co m calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) - days); return df.format(calendar.getTime()); } }