Jan 08

The ICU4J package provides a method for returning the available timezones for a given country code.

The following code will return a Map containing all available TimeZone’s for each country, keyed on country code.

public static Map<String, Set<TimeZone>> getAvailableTimeZones()
	Map<String, Set<TimeZone>> availableTimezones = 
		new HashMap<String, Set<TimeZone>>();
	// Loop through all available locales
	for (Locale locale : Locale.getAvailableLocales())
		final String countryCode = locale.getCountry();
		// Locate the timezones added for this country so far
		// (This can be moved to inside the loop if depending
		// on whether country with no available timezones should
		// be in the result map with an empty set, 
		// or not included at all)
		Set<TimeZone> timezones = availableTimezones.get(countryCode);
		if (timezones==null)
			timezones = new HashSet<TimeZone>();
			availableTimezones.put(countryCode, timezones);

		// Find all timezones for that country (code) using ICU4J
		for (String id : 
			// Add timezone to result map
	return availableTimezones;

written by objects \\ tags: , ,

2 Responses to “Can I find all available timezones for a country?”

  1. peter Says:


  2. worldclock Says:

    Can I find all available timezones for a country? | web development helpdesk – just great!

Leave a Reply

You must be logged in to post a comment.