Developer
Developer

Reputation: 6465

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

In my app I want to show timings of different countries like Japan UK USA France how can I do that?

Upvotes: 0

Views: 1053

Answers (2)

KingofBliss
KingofBliss

Reputation: 15115

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

Upvotes: 1

ipraba
ipraba

Reputation: 16553

Here is a sample code from apple related to time zones

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

Upvotes: 1

Related Questions