我在计算两个时区之间的时差时遇到问题。
如果我在位置 A,我知道纬度和经度以及当前时间。
我去位置B我知道纬度和经度以及当前时间。
如何计算当前两个点之间的时间差..(以UTC为单位)
首先获取一个可以转换纬度/经度以获取国家/地区和州/省的数据库或库。然后使用 NSTimeZone 类检索特定国家/地区的时区。您可以从许多站点购买此类数据库,即:http://www.ip2location.com/ http://www.ip2location.com/
要进行实际的转换,您需要执行以下操作:
NSTimeZone *sourceTimeZone =
[NSTimeZone timeZoneWithAbbreviation: @"GMT"];
NSTimeZone *destinationTimeZone =
[NSTimeZone timeZoneWithAbbreviation: @"EST"];
NSInteger sourceSeconds =
[sourceTimeZone secondsFromGMTForDate:date];
NSInteger destinationSeconds =
[destinationTimeZone secondsFromGMTForDate:date];
NSTimeInterval interval = destinationSeconds - sourceSeconds;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)