Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Arizona TimeZone Day Light Saving

Tags:

java

timezone

dst

I am trying to get current time in specific time zones. I tried following code.

Calendar j = new GregorianCalendar(TimeZone.getTimeZone("US/Mountain"));
j.setTimeInMillis(Calendar.getInstance().getTimeInMillis());
System.out.println(j.get(Calendar.HOUR_OF_DAY)+":"+j.get(Calendar.MINUTE));
TimeZone tz = TimeZone.getTimeZone("US/Mountain");
System.out.println("tz.getRawOffset()"+tz.getRawOffset()/3600);
System.out.println(tz.getDSTSavings());
System.out.println

(tz.inDaylightTime(new Date()));

The answer I got is surprising - 16:57 - wrong by 1 hr tz.getRawOffset()-7000 3600000 true - why daylight saving is true for Arizona? How to get the correct wall clock time of Phoenix or any other city in US?

like image 843
seawaves Avatar asked Dec 07 '22 01:12

seawaves


2 Answers

Arizona is in the Mountain timezone, but doesn't observe DST. If you specify the timezone "US/Mountain", then the computer will apply the rules used by most states in the Mountain time zone, which include observing daylight savings time. To get the rules for Arizona (which don't include DST), you want the timezone "US/Arizona" (or "America/Phoenix"). In the Navajo nation, you want the timezone named "Navajo".

To save yourself some of the trouble, always try to use the names from "America/*" where you can pick the name of a city that has the same timezone rules as the place you're interested in.

To get the correct time in the correct timezone for any given city in the world, you simply have to familiarize yourself with the names in the Olson timezone database and their meanings. While you usually think of the term "time zone" to mean the time of day in the middle of the winter (when everybody observes standard time), in the Olson database a timezone name represents the entire history of daylight savings time rules and timezone rules for a particular region.

As an example, even though Indiana now observes Eastern time and observes DST (except for a few counties right near Chicago which are on Central time like Chicago), before 2006 they didn't observe DST. A timezone named "US/Indiana" (or "America/Indianapolis") was created to cover this region, an even today, you would still want to use the timezone "America/Indianapolis" when talking about Indiana, so that queries about dates and times before 2006 could be answered correctly.

like image 75
Ken Bloom Avatar answered Dec 09 '22 14:12

Ken Bloom


Most of Arizona does not observe Daylight Savings Time, but the Navajo Nation inside Arizona does observe DST.

like image 38
John D. Cook Avatar answered Dec 09 '22 14:12

John D. Cook