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. import java.time.temporal.* ;
  10.  
  11. /* Name of the class has to be "Main" only if the class is public. */
  12. class Ideone
  13. {
  14. public static void main (String[] args) throws java.lang.Exception
  15. {
  16.  
  17. String input = "15:30:18" ;
  18. LocalTime lt = LocalTime.parse( input ) ;
  19.  
  20. String output1 = lt.toString() ;
  21.  
  22. // Localize to US.
  23. DateTimeFormatter f = DateTimeFormatter.ofLocalizedTime( FormatStyle.MEDIUM ).withLocale( Locale.US ) ;
  24. String output2 = lt.format( f ) ;
  25.  
  26. // Localize to Québec.
  27. DateTimeFormatter fQuébec = DateTimeFormatter.ofLocalizedTime( FormatStyle.MEDIUM ).withLocale( Locale.CANADA_FRENCH ) ;
  28. String output3 = lt.format( fQuébec ) ;
  29.  
  30. System.out.println( "lt.toString(): " + lt ) ;
  31. System.out.println( "output1: " + output1 ) ;
  32. System.out.println( "output2: " + output2 ) ;
  33. System.out.println( "output3: " + output3 ) ;
  34.  
  35. }
  36. }
Success #stdin #stdout 0.12s 38844KB
stdin
Standard input is empty
stdout
lt.toString(): 15:30:18
output1: 15:30:18
output2: 3:30:18 PM
output3: 15 h 30 min 18 s