xcode iPhone 的日期和时间在哪里获取时区列表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2985853/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where is the iPhone's Date & Time getting its time zone list
提问by user278859
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.
我可以使用 获取时区列表[NSTimeZone knownTimeZoneNames]
,但这仅提供时区 ID,其中每个时区包含一两个城市。
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.
我确实需要像日期和时间一样将选定的城市与其时区相关联。
回答by kennytm
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.
只有2个?在 3.1 上,[NSTimeZone knownTimeZoneNames]
返回一个包含 401 个元素的数组,地球上的时区远远少于 200 个。
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.
我很确定“其他应用程序”+knownTimeZoneNames
也会使用,因为这是返回此类列表的唯一公共方法。不过,请确保您的代码是正确的。
Settings.app uses the privateCPCityAPI from the privateAppSupport.framework. It does have San Francisco, but it's private.
Settings.app 使用来自私有AppSupport.framework的私有CPCityAPI 。它确实有旧金山,但它是私人的。
You need to create your own database (the data can be copied from /System/Library/PrivateFrameworks/AppSupport.framework/all_cities_adj.plist
).
您需要创建自己的数据库(可以从中复制数据/System/Library/PrivateFrameworks/AppSupport.framework/all_cities_adj.plist
)。
回答by Massimo Cafaro
What you are asking for is commonly referred to as the Olson database. See for instance this Wikipedia page. The public domain Zone.tabfile contains all of the timezones. You can find a zones.tab file in the zoneinfo directory of the libicaldistribution.
您所要求的通常称为 Olson 数据库。例如,请参阅此 Wikipedia 页面。公共域Zone.tab文件包含所有时区。您可以在libical发行版的 zoneinfo 目录中找到一个 zone.tab 文件。
回答by Gligor
I know it might be a late answer, but just in case someone else stumbles on it like I did the other day. I just open sourced a library that does exactly this. It is available as a CocoaPod and you can find it here:
我知道这可能是一个迟到的答案,但以防万一其他人像我前几天那样偶然发现它。我刚刚开源了一个可以做到这一点的库。它可以作为 CocoaPod 使用,您可以在这里找到它:
https://github.com/gligorkot/TimeZonePicker
https://github.com/gligorkot/TimeZonePicker
Also, thanks for all the replies above, they helped me in finding the correct cities database that is used for the Settings app.
另外,感谢上面的所有回复,他们帮助我找到了用于设置应用程序的正确城市数据库。