fork(1) download
  1. import java.time.Instant;
  2. import java.time.LocalDateTime;
  3. import java.time.ZonedDateTime;
  4. import java.time.ZoneId;
  5.  
  6. public class Main {
  7. public static void main(String[] args) {
  8. System.out.println("Local Europe/Madrid: " + LocalDateTime.now(ZoneId.of("Europe/Madrid")));
  9. System.out.println("Local system default: " + LocalDateTime.now(ZoneId.systemDefault()));
  10. System.out.println("Zoned Europe/Madrid: " + ZonedDateTime.now(ZoneId.of("Europe/Madrid")));
  11. System.out.println("Zoned system default: " + ZonedDateTime.now(ZoneId.systemDefault()));
  12. Instant instant = Instant.now();
  13. System.out.println("Local of Instant Europe/Madrid: " + LocalDateTime.ofInstant(instant, ZoneId.of("Europe/Madrid")));
  14. System.out.println("Local of Instant system default: " + LocalDateTime.ofInstant(instant, ZoneId.systemDefault()));
  15. System.out.println("Zoned of Instant Europe/Madrid: " + ZonedDateTime.ofInstant(instant, ZoneId.of("Europe/Madrid")));
  16. System.out.println("Zoned of Instant system default: " + ZonedDateTime.ofInstant(instant, ZoneId.systemDefault()));
  17. }
  18. }
Success #stdin #stdout 0.17s 60772KB
stdin
Standard input is empty
stdout
Local Europe/Madrid: 2024-11-13T19:16:44.552784
Local system default: 2024-11-13T18:16:44.618190
Zoned Europe/Madrid: 2024-11-13T19:16:44.618860+01:00[Europe/Madrid]
Zoned system default: 2024-11-13T18:16:44.619420Z[GMT]
Local of Instant Europe/Madrid: 2024-11-13T19:16:44.619960
Local of Instant system default: 2024-11-13T18:16:44.619960
Zoned of Instant Europe/Madrid: 2024-11-13T19:16:44.619960+01:00[Europe/Madrid]
Zoned of Instant system default: 2024-11-13T18:16:44.619960Z[GMT]