Reputation: 25
I'm trying to convert a time from a string to a Local Time. When converting, it is converting any time with :00 as the seconds to the hour and minute only...
12:00:00 AM -> 00:00
11:59:00 AM -> 11:59
I'm also going to convert 12 hour time to military but I can't correctly do that until it pulls the 12 hour time correctly.
LocalTimeStringConverter ltsc =
new LocalTimeStringConverter(DateTimeFormatter.ofPattern("hh:mm:ss a"),
DateTimeFormatter.ofPattern("hh:mm:ss a"));
LocalTime ltStartTime = (LocalTime) ltsc.fromString("12:00:00 AM");
How do I get it to pull the seconds so 12:00:00 AM
converts to 00:00:00
?
Upvotes: 0
Views: 1301
Reputation: 60036
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss");
String result = ltStartTime.format(formatter);
System.out.println(result);// 00:00:00
Upvotes: 2