import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
public class MainClass {
public static void main(String[] args) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
GregorianCalendar gc = new GregorianCalendar();
java.util.Date d = sdf.parse("12/12/2003");
gc.setTime(d);
System.out.println("Input Date = " + sdf.format(d));
int dayBefore = gc.get(Calendar.DAY_OF_YEAR);
gc.roll(Calendar.DAY_OF_YEAR, -1);
int dayAfter = gc.get(Calendar.DAY_OF_YEAR);
if(dayAfter > dayBefore) {
gc.roll(Calendar.YEAR, -1);
}
gc.get(Calendar.DATE);
java.util.Date yesterday = gc.getTime();
System.out.println("Yesterdays Date = " + sdf.format(yesterday));
}
}
Input Date = 12/12/2003
Yesterdays Date = 12/11/2003