Error with Joda-Time in Android: The datetime zone id 'America/New_York' is not recognised

一笑奈何 提交于 2021-01-21 06:52:29

问题


Exception:

Caused by: java.lang.IllegalArgumentException: The datetime zone id 'America/New_York' is not recognised

Android code:

DateTime dt = new DateTime();
DateTimeZone dtZone = DateTimeZone.forID("America/New_York");
DateTime dtus = dt.withZone(dtZone); 

Date dateInUS = dtus.toDate();
System.out.println(dateInUS);

Why am I getting this error?

I have loaded the Joda API in Gradle:

compile 'net.danlew:android.joda:2.7.1'

回答1:


I solved the error by adding:

public void onCreate() {
  super.onCreate();
  JodaTimeAndroid.init(this);
}


来源:https://stackoverflow.com/questions/29029502/error-with-joda-time-in-android-the-datetime-zone-id-america-new-york-is-not

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