fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.time.* ;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. Instant instant = Instant.now() ;
  14. System.out.println( instant ) ; // Standard ISO 8601 format.
  15.  
  16. List < ZoneId > zoneIds =
  17. List.of(
  18. ZoneId.of( "America/Juneau" ) ,
  19. ZoneId.of( "America/Los_Angeles" ) ,
  20. ZoneId.of( "America/Chicago" ) ,
  21. ZoneId.of( "America/New_York" )
  22. ) ;
  23.  
  24. for ( ZoneId zoneId : zoneIds )
  25. {
  26. ZonedDateTime zdt = instant.atZone( zoneId ) ;
  27. String output = zdt.toString() ; // Standard ISO 8601 format, wisely extended by appending the name of the time zone in square brackets.
  28. System.out.println( output ) ;
  29. }
  30. }
  31. }
Success #stdin #stdout 0.16s 44372KB
stdin
Standard input is empty
stdout
2023-03-27T04:23:55.441822Z
2023-03-26T20:23:55.441822-08:00[America/Juneau]
2023-03-26T21:23:55.441822-07:00[America/Los_Angeles]
2023-03-26T23:23:55.441822-05:00[America/Chicago]
2023-03-27T00:23:55.441822-04:00[America/New_York]