Here you can find the source of getBeforeDate(int day)
public static Date getBeforeDate(int day) throws Exception
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static Date getBeforeDate(int day) throws Exception { Calendar cl = Calendar.getInstance(); Long clTemp = cl.getTimeInMillis() - day * 24 * 60 * 60 * 1000L; cl.setTimeInMillis(clTemp);//from w w w . ja v a 2s . c om return getFormatDate(cl.getTime(), "yyyy-MM-dd"); } public static Date getFormatDate(Date date, String format) throws Exception { String dateStr = getDate2String(date, format); return getString2Date(dateStr, format); } public static String getDate2String(Date date, String format) { SimpleDateFormat sformat = new SimpleDateFormat(format); return sformat.format(date); } public static Date getString2Date(String date, String format) throws Exception { SimpleDateFormat sformat = new SimpleDateFormat(format); return sformat.parse(date); } }