A TimeZone is a Java class for a region of the earth that keeps the same time. If they
keep different time in summer and winter, everyone is the region flips together. The TimeZone
class describes the offset from UTC in summer and winter time and when the flips occur of a given timezone. To get the
default TimeZone adjusted for the user’s location:
In ordinary use, a time zone is a region of the earth that keeps the same winter time. They
may or may not all flip to summer time at the same time and some parts may not flip at all.
TimeZone Names and Offsets
The names for timezones used in Java comes from a database
maintained by Arthur David Olson. For reasons only
he understands, Pacific Standard Time is called America/Los_Angeles.
The reason that local time is different at different spots on the earth is a consequence of:
- The earth rotates on its axis.
- The earth rotates counter-clockwise when viewed looking down on the north pole.
- The earth rotates west to east.
- The sun ‘rises” in the east and sets in the west.
- In natural time, noon is when the sun is highest in the sky. This happens at one instant each day and at a different
instant each day for each degree of latitude.
- People “back east” get up earlier and go to bed earlier.
The reason we have time zones is to make synchronising railway (and later airline and TV) schedules easier. If we
used natural time, based on observing the instant the sun were highest in the sky, every town would have its own
slightly different clock from its immediate neighbours. This is how things used to be done in the days of the stagecoach.
You will see many different ways of specifying a time zone, including:
- Olson: America/Vancouver
- Posix: PST8PDT
- UTC relative UTC-8 UTC-7
Here is a list of available TimeZones:
If, tz, the above TimeZone Java Applet does not work…
- This Java Applet needs Java 1.6 or later, version 1.6.0_14 recommended and a recent browser.
- You should see the Applet above looking much like the screenshot. If you don’t, the following should help you get it working:
- If you are using Microsoft Internet Explorer, try another browser. Seriously. Microsoft has taken great pains, over and over, to screw up Java and every other multi-platform standardisation.
- If you are using Internet Explorer 7 or 8, you must allow blocked content permission for Active X to run. This also gives permission to Java to run. Click the Information bar, and then click Allow blocked content. Unfortunately, this also allows dangerous ActiveX code to run. However, you must do this in order to get access to perfectly-safe Java Applets running in a sandbox. This is part of Microsoft’s war on Java. Don’t put up with it! Use a different browser.
- Especially if this Applet has worked before, try clearing the browser cache and rebooting.
- To ensure your Java is up to date, check with Wassup. First, download it and run it as an application independent of your browser, then run it online as an Applet to add the complication of your browser.
- If the above Applet does not work, check the Java console for error messages.
- If the above Applet does not work, you might have better luck with the downloadable version.
- If you are using Mac OS X and would like an improved Look and Feel, download the QuaQua look & feel from randelshofer.ch/quaqua. UnZip the contained quaqua.jar and install it in ~/Library/Java/Extensions or one of the other ext dirs.
- If you still can’t get the program working click HELP for more detail.
- If you can’t get the above Applet working after trying the advice above and from the HELP button below, have bugs to report or ideas to improve the program or its documentation, please send me an email at
.
Get New Java Get New Browser
Help
- Add column 1 in hours to UTC to get local standard time.
- Add column 2 in hours to UTC to get local daylight saving time.
- Use UTC when you want no time zone at all.
- Use Asia/Riyadh for Arabia Standard Time. Asia/Riyadh87,
Asia/Riyadh88 and Asia/Riyadh89 are 3 hours and 7 minutes
east of UTC. This is the offset used in 1987 to 1989. Actually it
was 3 hours 7 minutes and 4 seconds to approximate solar time. Prior to 1950 they used 3:06:52.
In the period 1951— 1986 and 1990
onward they used a simple 3 hour difference. In Islamic tradition, the day starts at sunset.
- Note how much many aliases there are for the same timezone. I speculate there are two reasons for this:
- To anticipate some geographical region adopting a quirky daylight saving rule in future. There would be no need adjust
to a new split timezone to adopt the new rule. Only the tables built into Java would need to be adjusted.
- It makes it easier for people to find their own timezone. They need find only a nearby city without having to consult a
map to find a distant city on the same longitude. Often they can find their own city directly.
Gotchas
- Timezone names never contain spaces. They use underscores. e.g. America/Los_Angeles. In Linux, make sure /etc/sysconfig/clock
use official underscore names.
- Use UTC rather that GMT for the base time used internally. GMT is
London civil time and has a DST correction in summer. UTC stands for Coordinated Universal
Time, huh? not CUT? It was a weird compromise acronym half way between French and
English. GMT stands for Greenwich Mean Time.
See GNU Timezone classes that correct for historical changes
and leap seconds.
You can find out the current time at any place on the globe at WorldTimeServer.com.
It will tell you the offset from UTC, but not the timezone name.
Unfortunately, you can’t extract the rules about when daylight savings go into effect from a TimeZone
object. I suppose if you were patient you could deduce them by binary search on inDaylightTime.
You could also study the code that is used to construct all the TimeZone objects in rt.jar,
or the various locale jars and decompile and parse that to extract the information.
Here are the rules for the switch days in the
EU. There are some algorithms to compute
them.
Switch days are decided politically so can change erratically, especially in the USA, albeit with advance notice. In
ancient Rome, one could bribe officials to have months lengthened or shortened, so we have made progress.
Learning More
Sun’s Javadoc on the
TimeZone class : available: