Here you can find the source of getDateBefore(String d, int day)
public static String getDateBefore(String d, int day)
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; public class Main { public static String getDateBefore(String d, int day) { SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); Calendar now = Calendar.getInstance(); try {//ww w. j a v a2 s.c om now.setTime(format.parse(d)); now.set(Calendar.DATE, now.get(Calendar.DATE) - day); } catch (ParseException e) { e.printStackTrace(); } return format.format(now.getTime()); } }