fork(9) 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. import java.time.temporal.* ;
  10.  
  11.  
  12. /* Name of the class has to be "Main" only if the class is public. */
  13. class Ideone
  14. {
  15. public static void main (String[] args) throws java.lang.Exception
  16. {
  17.  
  18. ZoneId z = ZoneId.of( "Asia/Tokyo" ) ;
  19. LocalTime localTime = LocalTime.now( z ) ;
  20.  
  21. // Québec
  22. Locale locale_fr_CA = Locale.CANADA_FRENCH ; // Or `Locale.US`, and so on.
  23. DateTimeFormatter formatterQuébec = DateTimeFormatter.ofLocalizedTime( FormatStyle.SHORT ).withLocale( locale_fr_CA ) ;
  24. String outputQuébec = localTime.format( formatterQuébec ) ;
  25.  
  26. System.out.println( outputQuébec ) ;
  27.  
  28. // US
  29. Locale locale_en_US = Locale.US ;
  30. DateTimeFormatter formatterUS = DateTimeFormatter.ofLocalizedTime( FormatStyle.SHORT ).withLocale( locale_en_US ) ;
  31. String outputUS = localTime.format( formatterUS ) ;
  32.  
  33. System.out.println( outputUS ) ;
  34. }
  35. }
Success #stdin #stdout 0.12s 37496KB
stdin
Standard input is empty
stdout
10 h 31
10:31 AM