Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrate TimeZone to DateTimeZone

Tags:

java

jodatime

I am experimenting to Joda time.

    final String string_from_3rd_party = "GMT+08:00";
    // Works for standard Java TimeZone!
    System.out.println(TimeZone.getTimeZone(string_from_3rd_party));
    // Exception in thread "main" java.lang.IllegalArgumentException: The datetime zone id is not recognised: GMT+08:00
    System.out.println(DateTimeZone.forID(string_from_3rd_party));

How can I retain the string_from_3rd_party, yet, able to construct a Joda DateTimeZone out from it?

like image 655
Cheok Yan Cheng Avatar asked Oct 30 '10 08:10

Cheok Yan Cheng


1 Answers

You can use the Java TimeZone to create the DateTimeZone:

TimeZone timeZone = TimeZone.getTimeZone(string_from_3rd_party);
DateTimeZone dateTimeZone = DateTimeZone.forTimeZone(timeZone);
like image 62
Ventral Avatar answered Sep 29 '22 11:09

Ventral