Java SystemV timezones and JodaTime

前端 未结 3 714
暖寄归人
暖寄归人 2021-01-13 01:14

I am working with timezones in a Java application using JodaTime. I encounter a problem when trying to build a DateTimeZone (JodaTime) object from the id of a java timezone.

3条回答
  •  情深已故
    2021-01-13 01:34

    You can simply convert java TimeZone to DateTimeZone, using method DateTimeZone#forTimeZone

    TimeZone tz = //...  
    DateTimeZone dtz = DateTimeZone.forTimeZone(tz);  
    

    Some of this zones can be parsed without "SystemV/"

    So you can use

    String tzId = "SystemV/MST7MDT";
    DateTimeZone tz = DateTimeZone.forID(tzId.replaceAll("SystemV/", ""));  
    

    Also you can make next

    TimeZone tz = TimeZone.getTimeZone("SystemV/MST7MDT");
    DateTimeZone jodaTz = DateTimeZone.forTimeZone(tz);
    

提交回复
热议问题