Here you can find the source of getPreviousDate(int period)
public static Date getPreviousDate(int period)
//package com.java2s; //License from project: Open Source License import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Main { public static Date getPreviousDate(int period) { Date today = new Date(); Calendar calendar = new GregorianCalendar(); calendar.setTime(today);//from www. j a va 2 s . c o m if (period == 7) { calendar.add(Calendar.DATE, -7); } else if (period == 30) { calendar.add(Calendar.MONTH, -1); } else { calendar.add(Calendar.YEAR, -1); } return calendar.getTime(); } }