Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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'
like image 981
Rom Avatar asked Mar 13 '15 10:03

Rom


1 Answers

I solved the error by adding:

public void onCreate() {
  super.onCreate();
  JodaTimeAndroid.init(this);
}
like image 107
Rom Avatar answered Oct 18 '22 00:10

Rom