Android中的Joda-Time错误:无法识别日期时间区域ID"America/New_York" [英] Error with Joda-Time in Android: The datetime zone id 'America/New_York' is not recognised
本文介绍了Android中的Joda-Time错误:无法识别日期时间区域ID"America/New_York"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例外:
由以下原因引起:java.lang.IllegalArgumentException:无法识别日期时间区域ID美国/纽约"
Caused by: java.lang.IllegalArgumentException: The datetime zone id 'America/New_York' is not recognised
Android代码:
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);
为什么会出现此错误?
我已经在Gradle中加载了Joda API:
I have loaded the Joda API in Gradle:
compile 'net.danlew:android.joda:2.7.1'
推荐答案
我通过添加以下内容解决了该错误:
I solved the error by adding:
public void onCreate() {
super.onCreate();
JodaTimeAndroid.init(this);
}
这篇关于Android中的Joda-Time错误:无法识别日期时间区域ID"America/New_York"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文