Skip to content

Instantly share code, notes, and snippets.

@benjaminbojko
Created September 19, 2012 17:50
Show Gist options
  • Save benjaminbojko/3751079 to your computer and use it in GitHub Desktop.
Save benjaminbojko/3751079 to your computer and use it in GitHub Desktop.
Convert NodeJS JSON Date String to Objective C Date
// Modified version of an Apple Docs example that accomodates for the extra milliseconds used in NodeJS/JS dates
// https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html#//apple_ref/doc/uid/TP40002369-SW1
- (NSDate *)dateForRFC3339DateTimeString:(NSString *)rfc3339DateTimeString {
NSDateFormatter *rfc3339DateFormatter = [[NSDateFormatter alloc] init];
[rfc3339DateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'SSS'Z'"];
[rfc3339DateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
// Convert the RFC 3339 date time string to an NSDate.
NSDate *result = [rfc3339DateFormatter dateFromString:rfc3339DateTimeString];
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment