0
在我的应用我想展示不同国家的时序像 日本 英国 美国 法国 我该怎么办呢?如何显示在iPhone应用程序不同的时区不同的时钟
在我的应用我想展示不同国家的时序像 日本 英国 美国 法国 我该怎么办呢?如何显示在iPhone应用程序不同的时区不同的时钟
获取当前日期,
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];
嘿!感谢您的重播,但是如果我想获得法国和日本的现在时间,请告诉我。我必须做的,我的意思是我应该选择哪个时区。 – Developer 2010-12-07 12:41:59
你可以改变时区使用,[日历setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@“GMT”]]; – KingofBliss 2010-12-07 12:45:40