Here you can find the source of getYesterday(Date date, Boolean isBefore, int interval)
public static Date getYesterday(Date date, Boolean isBefore, int interval)
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; public class Main { public static final String YMD_HMS = "yyyy-MM-dd HH:mm:ss"; public static Date getYesterday(Date date, Boolean isBefore, int interval) { Calendar calendar = Calendar.getInstance(TimeZone.getDefault()); calendar.setTime(date);/* w w w . j a v a 2 s . c om*/ calendar.add(Calendar.DATE, isBefore ? -interval : +interval); return str2Date(date2Str(calendar.getTime())); } public static Date str2Date(String str) { Date d = null; SimpleDateFormat sdf = new SimpleDateFormat(YMD_HMS); try { d = sdf.parse(str); } catch (ParseException e) { e.printStackTrace(); } return d; } public static Date str2Date(String str, String pattern) { Date d = null; SimpleDateFormat sdf = new SimpleDateFormat(pattern); try { d = sdf.parse(str); } catch (ParseException e) { e.printStackTrace(); } return d; } public static String date2Str(Date date) { SimpleDateFormat sdf = new SimpleDateFormat(YMD_HMS); return sdf.format(date); } public static String date2Str(Date date, String format) { SimpleDateFormat sdf = new SimpleDateFormat(format); return sdf.format(date); } }