fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. import java.time.* ;
  8. import java.time.format.* ;
  9.  
  10. /* Name of the class has to be "Main" only if the class is public. */
  11. class Ideone
  12. {
  13. public static void main (String[] args) throws java.lang.Exception
  14. {
  15.  
  16. Instant instant = Instant.parse( "2022-04-19T15:30:14.348767Z" ) ;
  17.  
  18. ZoneId z = ZoneId.of( "America/Edmonton" ) ;
  19. ZonedDateTime zdt = instant.atZone( z ) ;
  20.  
  21. FormatStyle style = FormatStyle.SHORT ;
  22. Locale locale = Locale.CANADA_FRENCH ;
  23. DateTimeFormatter f = DateTimeFormatter.ofLocalizedDateTime( style ).withLocale( locale ) ;
  24. String output = zdt.format( f );
  25.  
  26. System.out.println( "instant.toString(): " + instant ) ;
  27. System.out.println( "zdt.toString(): " + zdt ) ;
  28. System.out.println( "output: " + output ) ;
  29. }
  30. }
Success #stdin #stdout 0.21s 54944KB
stdin
Standard input is empty
stdout
instant.toString(): 2022-04-19T15:30:14.348767Z
zdt.toString(): 2022-04-19T09:30:14.348767-06:00[America/Edmonton]
output: 22-04-19 09 h 30