androiddatetimejodatimejoda-convert

Convert 12 hour time to 24 hour using Joda time


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());

Solution

  • 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.