Skip to content

Instantly share code, notes, and snippets.

@armadsen
Last active August 29, 2015 14:01
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 armadsen/0c93770b2d70b340c081 to your computer and use it in GitHub Desktop.
Save armadsen/0c93770b2d70b340c081 to your computer and use it in GitHub Desktop.
/* 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