2010-12-07 85 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

相关问题