Jodatime issues on Android 5.0

和自甴很熟 提交于 2019-12-11 03:16:18

问题


My app has been working for some time, but after the release of Android 5.0 it crashes on devices running this version. I'm using JodaTime 2.6 for date handling and it's this library that suddenly throws the following exception:

java.lang.IllegalArgumentException: Invalid format: "6:06:00 AM" is malformed at "AM"

Ive verified that the corresponding string I'm trying to parse has the correct format.

UPDATE(Here is code that fails)

 private void doSomething(DateTime time, String timeToParse,int day, int month) {
    DateTimeFormatter fmt = DateTimeFormat.forPattern("h:mm:ss a");
    //Fails here: 
   LocalTime timeFromString = LocalTime.parse(timeToParse,fmt);
}

Anyone experience similar issues?


回答1:


This is probably a localization issue. It appears that your default local does not know the "AM"-string, but something else.

Joda-Time just delegates to the underlying JVM-resource, in your case to the Android-resources which can be different. To do so, Joda-Time finally uses the class DateFormatSymbols. Please check your locale and the output of getAmPmStrings() for a proper diagnosis.

Dependent on the result of the diagnosis either setting the locale explicitly by using LocalTime.parse(timeToParse, fmt.withLocale(Locale locale)); helps, or you use a suitable form of string input preprocessing.



来源:https://stackoverflow.com/questions/28286732/jodatime-issues-on-android-5-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!