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