开发者

How to show different clock from different time zones in iPhone app

In my app I want to show timings of dif开发者_如何学Cferent countries like Japan UK USA France how can I do that?


Get the current date by,

NSDate *today=[NSDate date];

Then using NSTimezone get the timings for different countries.

Sample code

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];


Here is a sample code from apple related to time zones

http://developer.apple.com/library/ios/#samplecode/TableViewSuite/Introduction/Intro.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜