获得军事时区的缩写

时间:2013-11-13 21:47:10

标签: java timezone jodatime abbreviation

我有一个org.joda.time.DateTime对象,我需要检索军事时区缩写(例如 T 表示UTC-07:00, U 表示UTC-对于UTC±00:00,08:00, Z

请参阅http://en.wikipedia.org/wiki/List_of_military_time_zones

以下是我目前的做法:

int offset = dt.getZone().toTimeZone().getRawOffset() / (60 * 60 * 1000);
String timeZoneCode = timeZoneCodeMap.get(offset);

其中timeZoneCodeMap是使用以下

条目初始化的HashMap<Integer, String>
timeZoneCodeMap.put(1, "A");
timeZoneCodeMap.put(2, "B");
timeZoneCodeMap.put(3, "C");
...
timeZoneCodeMap.put(-10, "W");
timeZoneCodeMap.put(-11, "X");
timeZoneCodeMap.put(-12, "Y");      
timeZoneCodeMap.put(0, "Z");

是否存在已包含时区到军事缩写的映射的函数或库(在Joda或其他情况下)?

如果有更好的方法来计算偏移量,请随时告诉我。

1 个答案:

答案 0 :(得分:2)

这是一个很小的代码,你不妨自己动手......

static final String MAPPING = "YXWVUTSRQPONZABCDEFGHIKLM";
...
  String timeZoneCode = MAPPING.substring(offset + 12, offset + 13);
相关问题