fork download
  1. import java.time.LocalTime;
  2. import java.time.LocalDateTime;
  3. import java.time.format.DateTimeFormatter;
  4. import java.util.Locale;
  5.  
  6. public class Main {
  7. public static void main(String[] args) {
  8. // Test
  9. System.out.println(timeConversion("10/22/2021 10:05:39PM"));
  10. }
  11.  
  12. public static LocalDateTime timeConversion(String s) {
  13. DateTimeFormatter dtfInput = DateTimeFormatter.ofPattern("MM/dd/yyyy[ h:m:sa]", Locale.ENGLISH);
  14. LocalDateTime time = LocalDateTime.parse(s, dtfInput);
  15. return time;
  16. // DateTimeFormatter dtfOutput = DateTimeFormatter.ofPattern("HH:mm:ss", Locale.ENGLISH);
  17. // return time.format(dtfOutput);
  18. }
  19. }
Success #stdin #stdout 0.13s 55424KB
stdin
Standard input is empty
stdout
2021-10-22T22:05:39