fork download
  1. import java.time.ZoneId;
  2. import java.time.ZonedDateTime;
  3. import java.time.format.DateTimeFormatter;
  4. import java.time.format.FormatStyle;
  5.  
  6. public class Main {
  7. public static void main(String[] args) {
  8. // ZoneId.systemDefault() returns the system default time zone.
  9. // Replace it as per your requirement e.g. ZoneId.of("Europe/London").
  10. ZonedDateTime now = ZonedDateTime.now(ZoneId.systemDefault());
  11. System.out.println(now);
  12.  
  13. // Some formatted string values
  14. System.out.println(now.format(
  15. DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL)));
  16. System.out.println(now.format(
  17. DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM)));
  18. System.out.println(now.format(
  19. DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mm:ss.SSS zzzz")));
  20. }
  21. }
Success #stdin #stdout 0.27s 59180KB
stdin
Standard input is empty
stdout
2024-10-24T17:27:04.039541Z[GMT]
Thursday, October 24, 2024 at 5:27:04 PM Greenwich Mean Time
Oct 24, 2024, 5:27:04 PM
2024-10-24 17:27:04.039 Greenwich Mean Time