fork download
  1. import java.util.Date;
  2. import java.util.Calendar;
  3. import java.text.*;
  4.  
  5. public class Main{
  6.  
  7. public static void main(String ar[]){
  8. Calendar cal = Calendar.getInstance();
  9.  
  10. System.out.println("Today's date= "+cal.getTime());
  11. //subtracting a day
  12. cal.add(Calendar.DATE, -1);
  13. //System.out.println("Yesterday's date= "+cal.getTime());
  14.  
  15. DateFormat dateFormat = new SimpleDateFormat("MMddyyyy");
  16. System.out.println(dateFormat.format(cal.getTime()));
  17. }
  18.  
  19. }
Success #stdin #stdout 0.24s 61832KB
stdin
Standard input is empty
stdout
Today's date= Wed May 15 09:15:13 GMT 2024
05142024