How to create a nice dropdown list of time zones matching java TimeZone (s)

What strategy do other webapps use to create a beautifully formatted list of time zones for user preferences?

I tried to just get all the time zones, but the list is long and not very well formatted for the user.

I just want to know how other people do it.

+4
source share
2 answers

The following code snippet

... String [] ids = TimeZone.getAvailableIDs(); for(String id:ids) { TimeZone zone = TimeZone.getTimeZone(id); int offset = zone.getRawOffset()/1000; int hour = offset/3600; int minutes = (offset % 3600)/60; System.err.println(String.format("(GMT%+d:%02d) %s", hour, minutes, id)); } ... 

displays formatted time zones, for example:

 (GMT+12:00) Pacific/Tarawa (GMT+12:00) Pacific/Wake (GMT+12:00) Pacific/Wallis (GMT+12:45) NZ-CHAT 

You might want to add filtering for different offsets and / or time zones specified in zone.getDisplayName(zone.useDaylightTime(), TimeZone.SHORT) .

+3
source

A simple way is to place the time zone identifiers in the list, not the time zones themselves. TimeZone.getAvailableIDs() returns values ​​such as GMT, Europe / Paris, America / New_York ...

0
source

All Articles