fork(1) 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. ZoneId z = ZoneId.of( "America/New_York" );
  16. ZonedDateTime zdt = ZonedDateTime.now( z );
  17. System.out.println( "zdt represented in standard ISO 8601 format: " + zdt.toString() );
  18.  
  19. Locale locale = Locale.US ;
  20. DateTimeFormatter f_US = DateTimeFormatter.ofLocalizedDateTime( FormatStyle.MEDIUM ).withLocale( locale ) ;
  21. String outputLocalized_US = zdt.format( f_US ) ;
  22. String outputLocalized_CA_fr = zdt.format( f_US.withLocale( Locale.CANADA_FRENCH ) ) ;
  23.  
  24. System.out.println( outputLocalized_US ) ;
  25. System.out.println( outputLocalized_CA_fr ) ;
  26.  
  27. System.out.println(
  28. ZonedDateTime
  29. .now( ZoneId.of( "America/New_York" ) )
  30. .format(
  31. DateTimeFormatter
  32. .ofLocalizedDateTime( FormatStyle.MEDIUM , FormatStyle.LONG )
  33. .withLocale( Locale.US )
  34. )
  35. );
  36. }
  37. }
Success #stdin #stdout 0.28s 56464KB
stdin
Standard input is empty
stdout
zdt represented in standard ISO 8601 format: 2021-10-20T16:48:46.807359-04:00[America/New_York]
Oct 20, 2021, 4:48:46 PM
20 oct. 2021 16 h 48 min 46 s
Oct 20, 2021, 4:48:46 PM EDT