Last active
December 19, 2015 01:39
-
-
Save popthestack/5877965 to your computer and use it in GitHub Desktop.
RFC 3339 date string in Objective C
This file contains 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
NSDate *now = [[NSDate alloc] init]; | |
NSTimeZone *localTimeZone = [NSTimeZone systemTimeZone]; | |
NSDateFormatter *rfc3339DateFormatter = [[NSDateFormatter alloc] init]; | |
NSLocale *enUSPOSIXLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]; | |
[rfc3339DateFormatter setLocale:enUSPOSIXLocale]; | |
[rfc3339DateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ssZ"]; | |
[rfc3339DateFormatter setTimeZone:localTimeZone]; | |
NSString *dateString = [rfc3339DateFormatter stringFromDate:now]; | |
NSLog(@"RFC 3339 datetime: %@", dateString); | |
// 2013-06-27T10:27:08-0600 | |
// 2013-07-22T15:09:30+0100 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So many thanks !
This fix 2 problems :