Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Military Time Zone Abbreviation

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.

like image 351
jewbix.cube Avatar asked Nov 13 '13 21:11

jewbix.cube


People also ask

How do you write time zones in military time?

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".

What is UTC time zone?

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".

Is UTC and military time the same?

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.


Video Answer


1 Answers

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);
like image 130
Eamonn O'Brien-Strain Avatar answered Sep 23 '22 12:09

Eamonn O'Brien-Strain