Skip to content

Instantly share code, notes, and snippets.

@pbyrne
Created November 19, 2009 19:42
Show Gist options
  • Save pbyrne/238990 to your computer and use it in GitHub Desktop.
Save pbyrne/238990 to your computer and use it in GitHub Desktop.
// Instance method in my XML Reader to easily read dates from the XML
// Pretty sure I have the date formatting right, per the link from the Apple documentation
// http://unicode.org/reports/tr35/tr35-4.html#Date_Format_Patterns
-(NSDate *)dateWithString:(NSString *)dateString {
NSDateFormatter * formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setDateFormat:@"yyyy-MM-DD HH:mm:ss ZZ"];
NSLog(@"Converting '%@' to '%@'", dateString, [formatter dateFromString:dateString]);
return [formatter dateFromString:dateString];
}
// Except everything is coming in as January
// Logging results
// "Converting '2010-09-23 00:00:00 -0500' to '2010-01-22 23:00:00 -0600'"
// "Converting '2011-11-11 00:00:00 -0500' to '2011-01-10 23:00:00 -0600'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment