Posted By

saturngod on 10/06/10


Tagged

timezone iPhoneSDK


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

bobbym245
synced
Tintenklecks
cnathan


TimeZone Convertor


 / Published in: Objective C
 

URL: http://stackoverflow.com/questions/1081647/how-to-convert-time-to-the-timezone-of-the-iphone-device/1082179#1082179

  1. // The date in your source timezone (eg. EST)
  2. NSDate* sourceDate = [NSDate date];
  3.  
  4. NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"EST"];
  5. NSTimeZone* destinationTimeZone = [NSTimeZone systemTimeZone];
  6.  
  7. NSInteger sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:sourceDate];
  8. NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:sourceDate];
  9. NSTimeInterval interval = destinationGMTOffset - sourceGMTOffset;
  10.  
  11. NSDate* destinationDate = [[[NSDate alloc] initWithTimeInterval:interval sinceDate:sourceDate] autorelease];

Report this snippet  

You need to login to post a comment.