fork download
  1. import java.text.SimpleDateFormat;
  2. import java.util.Calendar;
  3. import java.util.Locale;
  4. import java.util.TimeZone;
  5.  
  6. class Main {
  7. public static void main(String[] args) {
  8. SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss.SSS z yyyy", Locale.ENGLISH);
  9. sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
  10.  
  11. Calendar cal = Calendar.getInstance();
  12. System.out.println("After instantiation: " + sdf.format(cal.getTime()));
  13.  
  14. cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
  15. System.out.println("After configuring the Day of Month: " + sdf.format(cal.getTime()));
  16.  
  17. cal.set(Calendar.HOUR_OF_DAY, cal.getActualMinimum(Calendar.HOUR_OF_DAY));
  18. System.out.println("After configuring the Hour of day: " + sdf.format(cal.getTime()));
  19.  
  20. cal.set(Calendar.MINUTE, cal.getActualMinimum(Calendar.MINUTE));
  21. System.out.println("After configuring the Minutes: " + sdf.format(cal.getTime()));
  22.  
  23. cal.set(Calendar.SECOND, cal.getActualMinimum(Calendar.SECOND));
  24. System.out.println("After configuring the Seconds: " + sdf.format(cal.getTime()));
  25.  
  26. cal.set(Calendar.MILLISECOND, cal.getActualMinimum(Calendar.MILLISECOND));
  27. System.out.println("After configuring the Millis: " + sdf.format(cal.getTime()));
  28. }
  29. }
Success #stdin #stdout 0.38s 58128KB
stdin
Standard input is empty
stdout
After instantiation:                  Thu Jan 19 15:29:38.381 UTC 2023
After configuring the Day of Month:   Sun Jan 01 15:29:38.381 UTC 2023
After configuring the Hour of day:    Sun Jan 01 00:29:38.381 UTC 2023
After configuring the Minutes:        Sun Jan 01 00:00:38.381 UTC 2023
After configuring the Seconds:        Sun Jan 01 00:00:00.381 UTC 2023
After configuring the Millis:         Sun Jan 01 00:00:00.000 UTC 2023