Last active
August 29, 2015 14:01
-
-
Save armadsen/0c93770b2d70b340c081 to your computer and use it in GitHub Desktop.
Example of using NSDateFormatter for answer to http://stackoverflow.com/questions/23700556/getting-a-date-from-string-objective-c/23700701
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
/* Written for answer to http://stackoverflow.com/questions/23700556/getting-a-date-from-string-objective-c/23700701 | |
Compile and run like so: | |
$> clang DateFormatterExample.m -ObjC -std=c99 -fobjc-arc -framework Foundation | |
$> ./a.out | |
*/ | |
#import <Foundation/Foundation.h> | |
int main(int argc, char *argv[]) { | |
@autoreleasepool { | |
NSString *sDate = @"2014-05-16T16:15:07+01:00"; | |
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; | |
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZZZZZ"]; | |
NSDate *result = [dateFormatter dateFromString:sDate]; | |
NSLog(@"result: %@", result); //result: 2014-05-16 15:15:07 +0000 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment