我在计算两个时区之间的时间差方面有问题。

如果我在位置,AI知道纬度和经度和当前时间。我去位置BI知道纬度和经度和当前时间。

如何计算两个当前点之间的时间差。(在UTC中)

有帮助吗?

解决方案

首先,获取一个数据库或库,该数据库或库将LAT/Long转换以获取国家和州/省。然后使用NstimeZone类来检索特定国家的时区。您可以从许多站点购买此类数据库,即: 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;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top