获取军事时区缩写

2022-09-02 14:09:52

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

查看 http://en.wikipedia.org/wiki/List_of_military_time_zones

以下是我目前的做法:

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

其中 是 使用如下所示的条目初始化的timeZoneCodeMapHashMap<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

这是如此小的代码,你不妨自己做...

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

答案 2

推荐