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. DateTimeFormatter f =
  16. DateTimeFormatter
  17. .ofLocalizedDateTime( FormatStyle.SHORT, FormatStyle.MEDIUM );
  18.  
  19. ZonedDateTime dateTime = ZonedDateTime
  20. .of( 2020, 3, 5, 14, 47, 51, 123456789, ZoneId.systemDefault() );
  21.  
  22. List< Locale > locales =
  23. List.of(
  24. Locale.US ,
  25. Locale.UK ,
  26. new Locale( "pl" , "PL" ) ,
  27. new Locale( "cs" , "CZ" )
  28. );
  29.  
  30. for( Locale locale : locales )
  31. {
  32. System.out.println( locale.toString() + " " + dateTime.format( f.withLocale( locale ) ) );
  33. }
  34. }
  35. }
Success #stdin #stdout 0.18s 39540KB
stdin
Standard input is empty
stdout
en_US  3/5/20, 2:47:51 PM
en_GB  05/03/2020, 14:47:51
pl_PL  05.03.2020, 14:47:51
cs_CZ  05.03.20 14:47:51