fork(12) download
  1. import java.util.Date;
  2. import java.util.Calendar;
  3.  
  4. public class Main{
  5.  
  6. public static void main(String ar[]){
  7. Calendar cal = Calendar.getInstance();
  8.  
  9. System.out.println("Today's date= "+cal.getTime());
  10. //subtracting a day
  11. cal.add(Calendar.DATE, -1);
  12. System.out.println("Yesterday's date= "+cal.getTime());
  13.  
  14. }
  15.  
  16. }
Success #stdin #stdout 0.04s 246080KB
stdin
Standard input is empty
stdout
Today's date= Wed Jul 11 04:21:43 GMT 2012
Yesterday's date= Tue Jul 10 04:21:43 GMT 2012