用纬度/经度计算出时间? [英] Figure out time by latitude/longitude?

查看:152
本文介绍了用纬度/经度计算出时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是协议。我有一个位置的纬度/经度设置。我需要弄清楚当前时间是在那个位置。这是我之前得到它的方式:

  NSDateFormatter * theFormatter = [[NSDateFormatter alloc] init]; 
[theFormatter setDateFormat:@h:mm a];
NSDate * todaysdate = [NSDate date];
NSString * todaysDate = [theFormatter stringFromDate:todaysdate];
[theFormatter release];

但是,我意识到这将给用户当前位置的时间。是否有一个API在某个地方给我基于lat / lon对的时间?



提前感谢。

解决方案

不幸的是,时区(一般的时间)从来没有你想要的那么简单。



可以遵循jer的建议。经度范围从-180到180度,一天有24小时,所以你得到每个时区15度的经度。在0度经度中心这些时区,因此UTC从-7.5延伸到7.5,UTC + 1从7.5到22.5,UTC-1从-7.5到-22.5,依此类推。然后你会有一个非常简单的,错误的,如何使用时区的模型。



看看这个时区地图




  • 时区不好排序; UTC-1中的区域与UTC-3中的区域相邻。

  • UTC-9.5,UTC-4.5,UTC + 3.5,UTC + 5.75和UTC +


  • 一旦你完成了整理,你就可以开始考虑夏令时。


    Here's the deal. I have a latitude/longitude set of a location. I need to figure out what the current time is in that location. Here's how I was getting it before:

    NSDateFormatter *theFormatter = [[NSDateFormatter alloc] init];
    [theFormatter setDateFormat:@"h:mm a"];
    NSDate *todaysdate = [NSDate date];
    NSString *todaysDate = [theFormatter stringFromDate:todaysdate];
    [theFormatter release];
    

    However, I realized that this will give the time for the user's current location. Is there an API somewhere that gives me the time based off of a lat/lon pair?

    Thanks in advance.

    解决方案

    Unfortunately timezones (and time in general) is never as simple as you would like.

    For a simple approximation you can follow jer's suggestion. Longitude ranges from -180 to 180 degrees, there are 24 hours in a day, so you get 15 degrees of longitude per time zone. Center those time zones on 0 degrees longitude so UTC extends from -7.5 to 7.5, UTC+1 is from 7.5 to 22.5, UTC-1 is from -7.5 to -22.5, and so on. You would then have a very simplistic, and wrong, model of how we use time zones.

    Take a look at this map of time zones.

    • Time zones are not well ordered; regions in UTC-1 are adjacent to regions in UTC-3.
    • UTC-9.5, UTC-4.5, UTC+3.5, UTC+5.75, and UTC+13 are all valid time zones and actively in use.

    Once you get that sorted out then you can start to consider daylight savings time.

    这篇关于用纬度/经度计算出时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆