I am allowing users on my web app to schedule events based on time zones of their choice.
I want to present a good list of time zones to the end user and then conver
Just to complement the answer by tbruyelle I added a few more countries (e.g. Canada), removed the "/" portion of the filter and provided a means to sort the list.
public static void main(String[] args)
{
List simplifiedTimezoneList = getTimezoneIdList();
for (String tz : simplifiedTimezoneList)
System.out.println(tz);
}
public static List getTimezoneIdList()
{
String[] temp = TimeZone.getAvailableIDs();
List timezoneList = new ArrayList();
List simplifiedTimezoneList = new ArrayList();
for (String tz : temp)
{
timezoneList.add(tz);
}
Collections.sort(timezoneList);
String filterList = "Canada|Mexico|Chile|Cuba|Brazil|Japan|Turkey|Mideast|Africa|America|Asia|Atlantic|Australia|Europe|Indian|Pacific";
Pattern p = Pattern.compile("^(" + filterList + ").*");
for (String tz : timezoneList)
{
Matcher m = p.matcher(tz);
if (m.find())
{
simplifiedTimezoneList.add(tz);
}
}
return simplifiedTimezoneList;
}