开发者

How do you get the local timezone based on core location coordinates?

Is it possible in cocoa touch to get the local timezone of device based on the co开发者_JS百科ordinates from the gps? I saw this asked last year, but no answer...

All I really want is the number of hours difference from GMT, and I don't want to query a web service.

Or, can I ask the device what timezone it is set to?

Can it be done?


Use [NSTimeZone localTimeZone];

Edit: The returned object has a -(NSInteger)secondsFromGMT method you can use to figure out the difference from GMT.


It is not actually possible, unless date is actually included in the input. Why? Because the offset changes with time. Most commonly, there is the switch to daylight saving time in North America and summer time in Europe. Various locations make the switch at different times. Additionally, the formulae used to determine when to make the switch change over time. A few years ago in the US, for example, daylight saving time was extended. Then you have places like Guatemala that try out daylight saving time some times and then decide next year not to do it.

Bottom line, there is not a one to one relationship between GPS coordinates and timezone. There is a one to one relationship between coordinates + date and timezone, though. But it's a moving target.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜