I am creating a web application that will offer the user a list of available timezones. I don't want to see the entire list of timezones, however, because it's long and I don't need anything outside of one or two countries. Is there a way to filter for specific timezones, or based on country, or even several countries?
1 Answers
In Noda Time, you can filter TZDB time zones by country using the location information stored in TzdbDateTimeZoneSource.Default.ZoneLocations
.
Each ZoneLocation
has a ZoneId
(such as America/Los_Angeles
) and a two-letter country code, such as "US". You can use this to filter time zones to a country, as shown in this answer.
The only downside with that approach is that you are still left with only the time zone id to show the user. If you want to show something more friendly, like "Eastern Time" or "Central European Time", those values aren't in Noda Time. Instead, you can use the TimeZoneNames library.
With TimeZoneNames, one operation you can can do is to get time zones with their id's and their localized display names for a particular language. For example:
var zones = TZNames.GetTimeZonesForCountry("US", "en");
See the TimeZoneNames readme for additional operations and sample output.

- 1
- 1

- 230,703
- 74
- 448
- 575