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. System.out.println(
  16. ZonedDateTime.now(
  17. ZoneId.of( "Pacific/Auckland" )
  18. )
  19. .format(
  20. DateTimeFormatter
  21. .ofLocalizedDateTime( FormatStyle.LONG )
  22. .withLocale( Locale.GERMANY )
  23. )
  24. );
  25.  
  26. Instant instant = Instant.now();
  27.  
  28. OffsetDateTime odt = instant.atOffset( ZoneOffset.UTC ) ;
  29.  
  30. ZoneId z = ZoneId.of( "Asia/Tokyo" ) ;
  31. ZonedDateTime zdt = instant.atZone( z ) ;
  32.  
  33. Locale locale = Locale.CANADA_FRENCH ;
  34. DateTimeFormatter f = DateTimeFormatter.ofLocalizedDateTime( FormatStyle.FULL ).withLocale( locale ) ;
  35. String output = zdt.format( f ) ;
  36.  
  37. System.out.println( "instant = " + instant ) ;
  38. System.out.println( "odt = " + odt ) ;
  39. System.out.println( "zdt = " + zdt ) ;
  40. System.out.println( "output = " + output ) ;
  41. }
  42. }
Success #stdin #stdout 0.35s 62872KB
stdin
Standard input is empty
stdout
28. Februar 2022 um 10:30:06 NZDT
instant = 2022-02-27T21:30:06.564418Z
odt = 2022-02-27T21:30:06.564418Z
zdt = 2022-02-28T06:30:06.564418+09:00[Asia/Tokyo]
output = lundi 28 février 2022 à 06 h 30 min 06 s heure normale du Japon