2010-10-30 116 views
7

我正在试验Joda时间。将时区移植到DateTimeZone

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,但是,能够从它构建一个乔达DateTimeZone了呢?

回答

19

您可以使用Java的时区创建DateTimeZone:

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

这是没有考虑到夏令时,如果你有夏令一个TimeZone配置 – Woody 2017-04-06 21:41:59