开发者

How to use Objective-c NSTimeZone to convert system timezone to destination's local timezone?

I am working on a project which involved in converting current time on iPhone to target destination's time. For example, the application needs to convert current time (08:00) to Germany's local time.

I have information about timezone (like UTC +1) and tried to search about how to use NSTimeZone to convert the NSDate value, but it looks like I ha开发者_Go百科ve to ask your help here.

Could you give me any suggestion? or point me out for some solution?


The simplest thing is probably to use -[NSTimeZone secondsFromGMTForDate:] for each time zone, and then figure out the delta between the two:

NSInteger  offset1 = [timezone1 secondsFromGMTForDate: date];
NSInteger  offset2 = [timezone2 secondsFromGMTForDate: date];

return [date addTimeInterval: (offset1 - offset2);


Check out NSDateFormatter and its setTimeZone: method.


This guide on working with time zone differences from Apple might be a useful guide to follow.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜