Java SystemV timezones and JodaTime

前端 未结 3 684
暖寄归人
暖寄归人 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);
    
    0 讨论(0)
  • 2021-01-13 01:43

    The SystemV time-zone IDs are old and deprecated. However, you can make Joda-Time understand them by re-compiling the joda-time jar file with the systemv time-zone data file included. See the commented out lines in the systemv data file. (ie. uncomment the lines and rebuild the jar file).

    0 讨论(0)
  • 2021-01-13 01:50

    I'll add this as a new post, as it provides the answers to my question. SystemV timezones were used in an old UNIX OS, that was named, you guessed it, UNIX SYSTEM V. After discussing with my team, we decided that they are of no importance to non-programers and even to programmers nowadays. So we decided not to use them in our application.

    Some references about the SystemV timezones:

    • http://en.wikipedia.org/wiki/IANA_time_zone_database#Files_in_tzdata
    • http://en.wikipedia.org/wiki/System_V
    0 讨论(0)
提交回复
热议问题