如何使用NSTimeZone -timeZoneWithName:来自Rails ActiveSupport的城市名称? [英] How to use NSTimeZone -timeZoneWithName: with a city name from Rails ActiveSupport?
问题描述
如果我只有 Bangkok 或 Tokyo 这样的城市名称,我如何在
中提供时区参数[NSTimeZone timeZoneWithName :@亚洲/东京]
在城市前面还有大陆和斜线?
If I only have the city name like Bangkok or Tokyo, how can I supply a timezone parameter in
[NSTimeZone timeZoneWithName:@"Asia/Tokyo"]
where it also has continent and slash in front of city?
我已经尝试过 [NSTimeZone timeZoneWithName:@Tokyo]
,它不起作用。
I already tried [NSTimeZone timeZoneWithName:@"Tokyo"]
, it doesn't work.
推荐答案
谢谢对于答案人员,但看起来这些城市名称只是RailsActiveSupport :: TimeZone使用的格式。所以我只需要将它映射回来。映射在这里 - > http://api.rubyonrails.org/classes/ActiveSupport/TimeZone .html
Thanks for the answers guys, but it looks like those city names are just a format that Rails "ActiveSupport::TimeZone" uses. So I just have to map it back. The mapping is here -> http://api.rubyonrails.org/classes/ActiveSupport/TimeZone.html
它将RailsActiveSupport :: TimeZone格式的时区映射到iOS使用的另一种格式(例如International Date Line West=> Pacific / Midway,Midway Island=>Pacific / Midway,Samoa=>Pacific / Pago_Pago,...)。
It maps the timezone from Rails "ActiveSupport::TimeZone" format to another format that iOS uses (e.g. "International Date Line West" => "Pacific/Midway", "Midway Island" => "Pacific/Midway", "Samoa" => "Pacific/Pago_Pago", ... ).
I已创建 plist文件,其中包含可轻松用于映射的NSDictionary属性。
I have created a plist file containing a NSDictionary property that can easily be used for mapping.
编辑:更新版本(带有使用示例)对于Rails 3.2(感谢RJ Regenold!)
an updated version (with usage example) for Rails 3.2 (thanks RJ Regenold!)
这篇关于如何使用NSTimeZone -timeZoneWithName:来自Rails ActiveSupport的城市名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!