2010-10-30 6 views
7

Tôi đang thử nghiệm thời gian Joda.Di chuyển TimeZone thành 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)); 

Làm thế nào tôi có thể giữ lại string_from_3rd_party, tuy nhiên, có khả năng xây dựng một Joda DateTimeZone ra từ nó?

Trả lời

19

Bạn có thể sử dụng Java TimeZone để tạo ra các DateTimeZone:

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

này không được tính đến tiết kiệm ánh sáng ban ngày tài khoản nếu bạn có một TimeZone với tiết kiệm ánh sáng ban ngày cấu hình – Woody