Retrieving Information on All Available Time Zones

This example lists all time zones known by the JDK.
Date today = new Date(); // Get all time zone ids String[] zoneIds = TimeZone.getAvailableIDs(); // View every time zone for (int i=0; i<zoneIds.length; i++) { // Get time zone by time zone id TimeZone tz = TimeZone.getTimeZone(zoneIds[i]); // Get the display name String shortName = tz.getDisplayName(tz.inDaylightTime(today), TimeZone.SHORT); String longName = tz.getDisplayName(tz.inDaylightTime(today), TimeZone.LONG); // Get the number of hours from GMT int rawOffset = tz.getRawOffset(); int hour = rawOffset / (60*60*1000); int min = Math.abs(rawOffset / (60*1000)) % 60; // Does the time zone have a daylight savings time period? boolean hasDST = tz.useDaylightTime(); // Is the time zone currently in a daylight savings time? boolean inDST = tz.inDaylightTime(today); }
Here's a few time zone entries:
Id, Short Name, Long Name, Hour:Time from GMT ACT, CST, Central Standard Time (Northern Territory) 9:30 AET, EST, Eastern Summer Time (New South Wales) 10:0 AGT, ART, Argentine Time -3:0 ART, EET, Eastern European Time 2:0 AST, AKST, Alaska Standard Time -9:0 Africa/Abidjan, GMT, Greenwich Mean Time 0:0 Africa/Accra, GMT, Greenwich Mean Time 0:0 Africa/Addis_Ababa, EAT, Eastern African Time 3:0 Africa/Algiers, CET, Central European Time 1:0 Africa/Asmera, EAT, Eastern African Time 3:0 Africa/Bamako, GMT, Greenwich Mean Time 0:0 Africa/Bangui, WAT, Western African Time 1:0

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.