2010-12-07 30 views

回答

1

獲取當前日期,

NSDate *today=[NSDate date]; 

然後使用NSTimezone得到不同國家的時機。

示例代碼

NSDate* sourceDate = [NSDate date]; 

NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"JST"]; 
NSTimeZone* destinationTimeZone = [NSTimeZone systemTimeZone]; 

NSInteger sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:sourceDate]; 
NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:sourceDate]; 
NSTimeInterval interval = destinationGMTOffset - sourceGMTOffset; 

NSDate* destinationDate = [[[NSDate alloc] initWithTimeInterval:interval sinceDate:sourceDate] autorelease]; 
+0

嘿!感謝您的重播,但是如果我想獲得法國和日本的現在時間,請告訴我。我必須做的,我的意思是我應該選擇哪個時區。 – Developer 2010-12-07 12:41:59

+0

你可以改變時區使用,[日曆setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@「GMT」]]; – KingofBliss 2010-12-07 12:45:40

相關問題