Skip to content

Instantly share code, notes, and snippets.

@AquaGeek
Created February 29, 2012 15:50
Show Gist options
  • Select an option

  • Save AquaGeek/1941904 to your computer and use it in GitHub Desktop.

Select an option

Save AquaGeek/1941904 to your computer and use it in GitHub Desktop.
NSDate notes
#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