Skip to content

Instantly share code, notes, and snippets.

@ejknapp
Created December 8, 2009 01:39
Show Gist options
  • Select an option

  • Save ejknapp/251336 to your computer and use it in GitHub Desktop.

Select an option

Save ejknapp/251336 to your computer and use it in GitHub Desktop.
// Handling Flak dates
NSDateFormatter* dateFormatter;
...
@property (nonatomic, retain) NSDateFormatter *dateFormatter;
//In the init method of something
self.dateFormatter = [[NSDateFormatter alloc] init];
self.dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss'Z'";
- (NSDate *) createLocalDate:(NSDictionary *)messageDictionary forKey:(NSString *)key {
NSDate *sourceDate;
NSTimeZone *sourceTimeZone;
NSTimeZone *destinationTimeZone;
NSInteger sourceGMTOffset;
NSInteger destinationGMTOffset;
NSTimeInterval interval;
NSDate *destinationDate;
// The create date of the message returned by the Flak server
sourceDate = [self.dateFormatter dateFromString:[messageDictionary objectForKey:key]];
sourceTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
destinationTimeZone = [NSTimeZone systemTimeZone];
sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:sourceDate];
destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:sourceDate];
interval = destinationGMTOffset - sourceGMTOffset;
destinationDate = [[[NSDate alloc] initWithTimeInterval:interval sinceDate:sourceDate] autorelease];
return destinationDate;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment