views:

367

answers:

2

I can get a list of time zones with [NSTimeZone knownTimeZoneNames], but that only gives the time zone IDs which include one or two cities in each time zone.

The Date & Time settings has a great list of cities and I have seen a few other apps that have the same if not similar lookup lists.

Where do these lists come from?

I do need to relate a picked city to its time zone like Date & Time does.

+1  A: 

Only 2? On 3.1 the [NSTimeZone knownTimeZoneNames] returns an array of 401 elements, and there are much less than 200 timezones on the Earth.

I'm pretty sure "other apps" use +knownTimeZoneNames as well, since this is the only public method returning such list. Please make sure your code is correct, though.


Settings.app uses the private CPCity API from the private AppSupport.framework. It does have San Francisco, but it's private.

You need to create your own database (the data can be copied from /System/Library/PrivateFrameworks/AppSupport.framework/all_cities_adj.plist).

KennyTM
Each time zone has multiple cites, but from different locales. For example in the Pacific time zone the only US city I can find is Los Angeles, however you will find Vancouver which I believe is Vancouver BC. This I think accounts for the disparity between the number of actual time zones in the world and the number of cities in the list.
Kenny, Thanks that plist is going to be what I am looking for. Do you know anything about the list? It is a list of arrays that contain...item 0 = latitudeitem 1 = longitudeitem 2 = ?? time zone??item 3 = ?? time zone id ???item 4 = country abbreviationitem 5 = cityitem 6 = countryAny idea what item 2 is? it shows 1 for Honolulu and it should be -10. Also for all of the US cities it uses US/Eastern, US/Pacific, etc. As I understand it these are not valid time zone IDs. US/Pacific should be America/Los Angeles.No problem, I can us Lat/Long to get time zone.thanks again,John
@johnbdh: Open the file with a text editor. 'TimeZoneIndex 0-27 used to show timezone "band"'. Probably not very usable. You have to match field 4 "TimeZone file" with the time zone name you get from NSTimeZone it seems. Also this list has only 211 entries, whereas I got some 400 entries from the public API. But this list contains a lot of cities not on the other list... Have to look into this more. Will probably combine the lists. But thanks for asking this question, I had also noticed that there were more cities in the Settings app than I could get from the API.
Felixyz
A: 

What you are asking for is commonly referred to as the Olson database. See for instance this Wikipedia page. The public domain Zone.tab file contains all of the timezones. You can find a zones.tab file in the zoneinfo directory of the libical distribution.

unforgiven