Posted By

paki on 05/23/11


Tagged

time


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

dvel


Get Local Phone Time


 / Published in: Objective C
 

  1. - (NSDate*)getLocalTime:(NSDate*)sourceDate
  2. {
  3. NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
  4. NSTimeZone* destinationTimeZone = [NSTimeZone systemTimeZone];
  5.  
  6. NSInteger sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:sourceDate];
  7. NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:sourceDate];
  8. NSTimeInterval interval = destinationGMTOffset - sourceGMTOffset;
  9.  
  10. NSDate* destinationDate = [[[NSDate alloc] initWithTimeInterval:interval sinceDate:sourceDate] autorelease];
  11. return destinationDate;
  12. }

Report this snippet  

You need to login to post a comment.