Created
February 29, 2012 15:50
-
-
Save AquaGeek/1941904 to your computer and use it in GitHub Desktop.
NSDate notes
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
| #import <Foundation/Foundation.h> | |
| int main (int argc, const char * argv[]) | |
| { | |
| @autoreleasepool { | |
| NSString *dateString = @"8:56pm 29 Feb"; | |
| NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; | |
| [formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]]; | |
| [formatter setDateFormat:@"h:mma d MMM"]; | |
| // date will be nil after the following line - without the year, the formatter doesn't know 29 is a valid day for Feb | |
| NSDate *date = [formatter dateFromString:dateString]; | |
| NSLog(@"Date: %@", date); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment