如何计算两个地点之间的时差

发布于 2024-08-06 03:42:20 字数 118 浏览 5 评论 0原文

我在计算两个时区之间的时差时遇到问题。

如果我在某个位置,人工智能知道纬度和经度以及当前时间。 我去位置BI知道纬度和经度以及当前时间。

如何计算当前两个点之间的时间差..(以UTC为单位)

I am having a problem with calculating time difference between two timeZones.

If I am at location A I know the latitude and longitude and the current time.
I go to location B I know the latitude and longitude and the current time.

How to calculate the time difference between the two current points .. (in UTC)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倾`听者〃 2024-08-13 03:42:20

首先获取一个可以转换纬度/经度以获取国家/地区和州/省的数据库或库。然后使用 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;

Firstly get a database or library that converts lat/long to get the country and state/province. Then use the NSTimeZone class to retrieve the timezone for a particular country. You can purchase such databases from many sites, ie:
http://www.ip2location.com/

To do the actual conversion you would do something like this:

NSTimeZone *sourceTimeZone =
    [NSTimeZone timeZoneWithAbbreviation: @"GMT"];
NSTimeZone *destinationTimeZone =
    [NSTimeZone timeZoneWithAbbreviation: @"EST"];

NSInteger sourceSeconds =
    [sourceTimeZone secondsFromGMTForDate:date];
NSInteger destinationSeconds =
    [destinationTimeZone secondsFromGMTForDate:date];
NSTimeInterval interval = destinationSeconds - sourceSeconds;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文