如何在iPhone应用程序中显示来自不同时区的不同时钟

时间:2010-12-07 12:29:49

标签: iphone

在我的应用中,我想展示不同国家的时间表 日本 联合王国 美国 法国     我怎么能这样做?

2 个答案:

答案 0 :(得分: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];

答案 1 :(得分:1)