Convert 12 hour time to 24 hour using Joda time

2.6k Views Asked by At

I am getting this error Invalid format: "09:30 PM" is malformed at " PM"

LocalTime start = new LocalTime();
LocalTime end = new LocalTime();
DateTimeFormatter formatter = DateTimeFormat.forPattern("hh:mm a");
start = formatter.parseLocalTime(from.toLowerCase());
end = formatter.parseLocalTime(to.toLowerCase());
1

There are 1 best solutions below

1
On BEST ANSWER

Your Pattern is incorrect. Please use the following:

DateTimeFormatter formatter= DateTimeFormat.forPattern("hh:mm aa");

Edit: Here is a link to the Documentation for DateTimeFormat.