Get Local Phone Time


/ Published in: Objective C
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.