2009-09-24 107 views
3

我在計算兩個時區之間的時間差時遇到問題。如何計算兩個位置之間的時間差

如果我在地點A,我知道經緯度和當前時間。 我去的位置B我知道經緯度和當前時間。

如何計算..兩個當前點之間的時間差(以UTC)

+0

只是減去位置的當前時間從當前時間位置B.還是我誤解了一些東西? – artagnon 2009-09-24 11:17:34

+0

是的,他希望通過經度做出來,烏拉圭回合的答案latitud – Jacob 2009-09-25 11:19:46

回答

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; 
+0

嘿感謝.. 我的意思是我這樣做的方式與時區.. NSTimeZone * sourceTimeZone = [NSTimeZone timeZoneWithName:[的NSString stringWithFormat:@「%@ 」 @ 「美國/梅諾米尼」]]; \t NSTimeZone * destinationTimeZone = [NSTimeZone timeZoneWithName:[NSString stringWithFormat:@「%@」,@「America/Juneau」]]; \t \t NSDate * date1 = [NSDate date]; \t NSInteger sourceSeconds = [sourceTimeZone secondsFromGMTForDate:date1]; \t NSInteger destinationSeconds = [destinationTimeZone secondsFromGMTForDate:date1]; \t NSTimeInterval interval = destinationSeconds - sourceSeconds; 再次感謝 – Sneha 2009-09-29 09:03:20

+0

你知道如何計算日間時間和在那個位置的夜間時間 – Sneha 2009-09-29 09:05:05

+0

,因爲在每個地方日落和日出的時間將有所不同http://www.mindspring.com/~cavu/sunset .html我已經得到了這個表格,我們cn實際上找出了區別,所有但不知道如何實現它:( – Sneha 2009-09-29 09:09:10

相關問題