Skip to content

Instantly share code, notes, and snippets.

@pietrorea
Created July 30, 2014 00:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pietrorea/15a0697f2aaf6d682ac6 to your computer and use it in GitHub Desktop.
Save pietrorea/15a0697f2aaf6d682ac6 to your computer and use it in GitHub Desktop.
Convert RFC 3339 formatted date string to NSDate
//From https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatting10_4.html
- (NSDate *)dateFromRFC3339String:(NSString *)dateString {
static NSDateFormatter *sRFC3339DateFormatter = nil;
if (sRFC3339DateFormatter == nil) {
sRFC3339DateFormatter = [[NSDateFormatter alloc] init];
NSLocale *enUSPOSIXLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
[sRFC3339DateFormatter setLocale:enUSPOSIXLocale];
[sRFC3339DateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"];
[sRFC3339DateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
}
// Convert the RFC 3339 date time string to an NSDate.
NSDate *date = [sRFC3339DateFormatter dateFromString:dateString];
return date;
}
@pietrorea
Copy link
Author

Useful for In-App purchase StoreKit receipt validation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment