Here you can find the source of getDateBefore(Date d, int day)
public static Date getDateBefore(Date d, int day) throws Exception
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.*; public class Main { public static Date getDateBefore(Date d, int day) throws Exception { Calendar now = Calendar.getInstance(); now.setTime(d);// w w w .j av a2 s . c o m now.set(Calendar.DATE, now.get(Calendar.DATE) - day); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = simpleDateFormat.parse(simpleDateFormat.format(now.getTime())); return date; } }