3

2つのタイムゾーン間の時間差の計算に問題があります。

私が場所AIにいる場合、緯度と経度、および現在の時刻を知っています。私は場所BIに行き、緯度と経度、そして現在の時刻を知っています。

2つの現在のポイント間の時間差を計算する方法..(UTC)

4

1 に答える 1

4

まず、緯度/経度を変換して国と州/県を取得するデータベースまたはライブラリを取得します。次に、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;
于 2009-09-24T13:14:36.377 に答える