fork(15) 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.temporal.* ;
  9. import java.time.format.* ;
  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. DateTimeFormatter formatterInput =
  17. DateTimeFormatter.ofPattern( // Define a formatting pattern to match your input text.
  18. "hh:mm a" ,
  19. Locale.US // `Locale` determines the human language and cultural norms used in localization. Needed here to translate the `AM` & `PM` value.
  20. ) ;
  21.  
  22. LocalTime lt =
  23. LocalTime.parse( // Class representing a time-of-day value without a date and without a time zone.
  24. "03:30 PM" ,
  25. formatterInput
  26. ) ;
  27.  
  28. DateTimeFormatter formatterOutput =
  29. DateTimeFormatter.ofPattern( // Define a formatting pattern to match your input text.
  30. "HH:mm" ,
  31. Locale.US // `Locale` determines the human language and cultural norms used in localization. Needed here to translate the `AM` & `PM` value.
  32. ) ;
  33. String output = lt.format( formatterOutput ) ;
  34.  
  35. System.out.println( "output: " + output ) ;
  36. }
  37. }
Success #stdin #stdout 0.17s 2184192KB
stdin
Standard input is empty
stdout
output: 15:30