Created
July 30, 2014 00:48
-
-
Save pietrorea/15a0697f2aaf6d682ac6 to your computer and use it in GitHub Desktop.
Convert RFC 3339 formatted date string to NSDate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Useful for In-App purchase StoreKit receipt validation