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