Saeed Masoumi
Saeed Masoumi

Reputation: 8916

Joda - "hh:mm AM" is malformed at "AM"

I'm using Joda library for formatting strings like hh:mm am/pm to LocalTime in my android app, So I'm using this:

  DateTimeFormat.forPattern("hh:mm a").parseLocalTime("6:30 AM");

It works fine, But when I change my phone language (to germany or spanish) it throwns this exception:

W/System.err﹕ java.lang.IllegalArgumentException: Invalid format: "06:30 AM" is malformed at "AM"

Any Ideas?

Upvotes: 2

Views: 1886

Answers (2)

user5182182
user5182182

Reputation:

Try this using locale English:

DateTimeFormat.forPattern("hh:mm a").withLocale(Locale.ENGLISH).parseLocalTime("6:30 AM");

Upvotes: 7

dieter_h
dieter_h

Reputation: 2727

Try:

 DateTimeFormat.forPattern("h:mm aa").parseLocalTime("6:30 AM");

Upvotes: 0

Related Questions