Here you can find the source of yesterdayDate()
public static Date yesterdayDate()
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { public static Date yesterdayDate() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar c = Calendar.getInstance(); c.add(Calendar.DATE, -1); return StringToDate(sdf.format(c.getTime())); }/*from w w w.j av a2 s . c o m*/ public static Date StringToDate(String dateStr) { SimpleDateFormat sdf = null; Date date = null; if (dateStr.length() > 10) { if (dateStr.indexOf("T") > -1) { dateStr = dateStr.replace("T", " "); } sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); } else { sdf = new SimpleDateFormat("yyyy-MM-dd"); } try { date = sdf.parse(dateStr); } catch (java.text.ParseException e) { e.printStackTrace(); return null; } return date; } }