I have a org.joda.time.DateTime
object and I need to retrieve the military time zone abbreviation (e.g. T for UTC-07:00, U for UTC-08:00, Z for UTC±00:00).
See http://en.wikipedia.org/wiki/List_of_military_time_zones
Here's how I'm currently doing it:
int offset = dt.getZone().toTimeZone().getRawOffset() / (60 * 60 * 1000);
String timeZoneCode = timeZoneCodeMap.get(offset);
where timeZoneCodeMap
is a HashMap<Integer, String>
that is initialized with entries like the following
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");
Does there exist a function or library (in Joda or otherwise) that already contains a mapping of time zones to military abbreviations?
Feel free to let me know if there is a better way to calculate the offset as well.
Going west from Greenwich, letters "November" to "Yankee" represent zones with negative offsets. The letters are typically used in conjunction with military time. For example, 6:00 a.m. in zone UTC−5 is written "0600R" and spoken "zero six hundred Romeo".
Prior to 1972, this time was called Greenwich Mean Time (GMT) but is now referred to as Coordinated Universal Time or Universal Time Coordinated (UTC). It is a coordinated time scale, maintained by the Bureau International des Poids et Mesures (BIPM). It is also known as "Z time" or "Zulu Time".
UTC uses 24-hour (military) time notation and is based on the local standard time on the 0° longitude meridian which runs through Greenwich, England. Midnight in Greenwich corresponds to 00:00 UTC, noon corresponds to 12:00 UTC, and so on.
This is such little code, that you might as well just do it yourself ...
static final String MAPPING = "YXWVUTSRQPONZABCDEFGHIKLM";
...
String timeZoneCode = MAPPING.substring(offset + 12, offset + 13);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With