Java tutorial
//package com.java2s; //License from project: Open Source License import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static String getBeforeTodayWithFormat(int gap, String dateFormat) { Calendar currentCalendar = Calendar.getInstance(); currentCalendar.add(Calendar.DATE, gap); Date date = currentCalendar.getTime(); SimpleDateFormat format = new SimpleDateFormat(dateFormat); return format.format(date); } }