It is necessary that Daylight Savings is not disabled.
-
http://stackoverflow.com/questions/8265592/why-is-the-timezone-gettimezonemst-method-is-different-from-gettimezoneus - For the record only and help other developer – Vicky Thakor Jul 18 '16 at 04:52
2 Answers
Well, in this list of zoneinfo time zone names there are plenty which claim to be "Mountain Time". Find the one that best fits what you want, and use that. For example:
TimeZone zone = TimeZone.getTimeZone("America/Denver");

- 1,421,763
- 867
- 9,128
- 9,194
-
8+1 - java also accepts getTimeZone("US/Mountain") which to me is clearer - if you don't know the specific city, but I can't argue with the standard of names that you reference. You could run into trouble if you picked a different city (ie Phoenix) with non-standard DST rules. – robert_x44 Jan 20 '11 at 23:11
-
2@RD01: I'd say that "America/Denver" is clearer precisely *for* that reason - because it's more precise, and therefore easier to predict. Given the various "mountain time" entries in the zoneinfo list, I wouldn't like to guess what I'd get just from using "US/Mountain". – Jon Skeet Jan 20 '11 at 23:43
-
1I understand what you're saying, but if you don't know what city you want, you can't be precise. I'd rather have the generic Mountain which works for almost the entire zone, than a city that might have specific rules (although some of these are being phased out). Picking the city is great when you're asking a user, who presumably knows. – robert_x44 Jan 21 '11 at 00:03
-
3@robert_x44 Those 3-4 letter abbreviations are not real time zones, not standardized, and are not unique(!). Use [proper time zone names](https://en.m.wikipedia.org/wiki/List_of_tz_database_time_zones) in the format of `continent/region`. We are not saying the user lives in Denver, but rather the time zone for the entire *region* is named “America/Denver”. – Basil Bourque Aug 12 '16 at 16:40
java.time
The java.util
Date-Time API is outdated and error-prone. It is recommended to stop using it completely and switch to the modern Date-Time API*.
Use ZoneId#of
instead of Timezone#getTimeZone
e.g.
ZoneId zoneId = ZoneId.of("America/Denver");
Learn more about the modern Date-Time API from Trail: Date Time.
Note: Check Mountain Time Zone and List of tz database time zones and choose a timezone ID that meets your requirement.
* For any reason, if you have to stick to Java 6 or Java 7, you can use ThreeTen-Backport which backports most of the java.time functionality to Java 6 & 7. If you are working for an Android project and your Android API level is still not compliant with Java-8, check Java 8+ APIs available through desugaring and How to use ThreeTenABP in Android Project.

- 71,965
- 6
- 74
- 110