【问题标题】:How to calculate the time difference between two locations如何计算两个位置之间的时间差
【发布时间】:2009-09-24 10:35:36
【问题描述】:

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

如果我在位置 A,我知道纬度和经度以及当前时间。 我去位置 B 我知道经纬度和当前时间。

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

【问题讨论】:

  • 只需从位置 B 的当前时间减去位置 A 的当前时间。还是我误解了什么?
  • 是的,他想按经度和纬度来做

标签: objective-c cocoa nstimezone


【解决方案1】:

首先获取一个数据库或库,将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;

【讨论】:

  • 嘿,谢谢你的回答.. 我的意思是我用 timeZone 这样做了.. NSTimeZone *sourceTimeZone =[NSTimeZone timeZoneWithName:[NSString stringWithFormat:@"%@",@"America/Menominee" ]]; NSTimeZone *destinationTimeZone =[NSTimeZone timeZoneWithName:[NSString stringWithFormat:@"%@",@"America/Juneau"]]; NSDate *date1=[NSDate 日期]; NSInteger sourceSeconds = [sourceTimeZone secondsFromGMTForDate:date1]; NSInteger destinationSeconds =[destinationTimeZone secondsFromGMTForDate:date1]; NSTimeInterval 间隔 = destinationSeconds - sourceSeconds;再次感谢
  • 你知道如何计算那个位置的白天时间和晚上时间吗
  • 因为每个地方的日落和日出时间都会不同mindspring.com/~cavu/sunset.html我有这个表格,我们实际上发现了不同之处,但不知道如何实现它:(
  • 很久以前,我确实在网上看到了一些代码,它根据经度和纬度计算日出/日落。如果你在谷歌上看,我相信你可以找到它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-13
相关资源
最近更新 更多