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. ZoneId z = ZoneId.of( "America/Montreal" ) ;
  17. LocalTime lt = LocalTime.now( z ) ;
  18.  
  19. DateTimeFormatter f = DateTimeFormatter.ofPattern( "hh:mm a" ) ; // Lowercase `hh` for 12-hour clock, uppercase `HH` for 24-hour clock.
  20. String output = lt.format( f ) ;
  21.  
  22. Locale locale = Locale.US ;
  23. DateTimeFormatter f2 = DateTimeFormatter.ofLocalizedTime( FormatStyle.SHORT ).withLocale( locale ) ;
  24. String output2 = lt.format( f2 ) ;
  25.  
  26. System.out.println( "lt.toString(): " + lt ) ;
  27. System.out.println( "output: " + output ) ;
  28. System.out.println( "output2: " + output2 ) ;
  29. }
  30. }
Success #stdin #stdout 0.25s 36248KB
stdin
Standard input is empty
stdout
lt.toString(): 22:09:39.313
output: 10:09 PM
output2: 10:09 PM