How do I get TimeZone descriptions - which countries a TimeZone is for - so I can display eg (GMT-9.00), Alaska (GMT-8.00), Pacific Time(US & Canada) etc

Joe Sam Shirah

Use the java.util.TimeZone and SimpleTimeZone classes. TimeZone has a static method, getAvailableIDs(), which returns all IDs supported. With this information, you can obtain TimeZones ( should be SimpleTimeZone objects ) from the static method TimeZone.getTimeZone( String ID ). From there you can get DisplayNames, Offsets and so on. The getOffset method wants a lot of information that means you will probably have to create multiple GregorianCalendars and mentions that "In general, clients should use Calendar.get(ZONE_OFFSET) + Calendar.get(DST_OFFSET) instead of calling this method." This should give you all the information to generate the Strings you need.

Since this is fairly intensive for interactive purposes, you may want to run the generation phase during off periods for the local ( to the user ) time zone(s), save the generated data to a file and pull it up at runtime. For any single time zone, short of changes in the law, this would really only need to be run twice a year to account for Daylight Savings Time changes.

About | Sitemap | Contact