将TimeZone迁移到DateTimeZone

时间:2010-10-30 08:00:49

标签: java jodatime

我正在试试Joda时间。

    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));

如何保留string_from_3rd_party,但能够从中构建Joda DateTimeZone

1 个答案:

答案 0 :(得分:22)

您可以使用Java TimeZone创建DateTimeZone:

TimeZone timeZone = TimeZone.getTimeZone(string_from_3rd_party);
DateTimeZone dateTimeZone = DateTimeZone.forTimeZone(timeZone);