[tz] Getting offset for each time zones
mj1856 at hotmail.com
Wed May 18 15:58:06 UTC 2016
> I wanted to get UTC offset for each time zone which is present under zoneinfo folder.
In general, you cannot get a single offset for most time zones, as each time zone represents a series of one or more offsets and the transitions between them. For example, America/Los_Angeles uses UTC-8 during standard time, and uses UTC-7 during daylight saving time. You could get the *current* offset for each zone, but your list will vary depending on when you generate it. You could get the *standard* offset for each zone, but even the standard offsets have changed over time, so they would only be the *current standard* offsets. Additionally consider that in some zones the daylight time is a larger portion of the year than the standard time, and in general the list would not be representative of any set of offsets that were actually in effect all at the same point in time.
> basically I wanted to create a drop down for all timezones with UTC offset, where user can select timezone.
The TZ project maintains lists in the zone.tab and zone1970.tab files that can assist in one particular way of selecting a time zone. You can consider building your list using these files. However, recognize that currently the comments in the file are only presented in English. If you are targeting a worldwide audience, then you have to pull in resources from the Unicode CLDR project to assist.
If you were looking for specific code to implement, that depends highly on your particular platform and language, and would be better asked on a site like Stack Overflow than here.
I'll also add that time zone selection is indeed a challenging problem, and there are alternative approaches to consider. These include map-based time zone pickers, lat/lon lookup via shapefiles, type-ahead style selection of associated cities (which requires even more data), multiple dropdowns used in succession, and others. Since most implementations don't make this easy, it's common to see a single dropdown with a long list of all TZ identifiers - even though that's not the recommended. You may want to spend some time looking at how various platforms differ in how they ask users to pick a time zone (mac vs linux vs windows), as well as web sites and applications such as Google Calendar. You may even want to try doing it in some language other than English to see what kind of differences there are. You'll find quite a lot of variation indeed.
In general, I don't think the world has settled on a single right way for a user to pick a time zone.
More information about the tz