How do you interpret dates with NSDateFormatter?
Apple Docs says NSDateFormatter uses Unicode for the specification. I read the spec, but I'm having trouble interpreting this date:
NSDateFormatter *frm = [[NSDateFormatter alloc] init];
[frm setDateFormat:@"EEE MMM dd HH:mm:ss ZZZ yyyy"];
NSLog(@"Tue Oct 13 09:24:15 +0000 2009 becomes %@", [frm dateFromString:@"Tue Oct 13 09:24:15 +0000 2009"]);
This code prints:
2009-10-13 11:37:40.334 test2[1704:20b] Tue Oct 13 09:24:15 +0000 2009 becomes (null)
+1
source to share
1 answer
Sorry, people get it already. NSDateFormatter uses the current system locale by default. In the above code example, it fails if you set the locale of your system to something other than US To fix this, before setting the locale to the string used by your date string, e.g .:
[frm setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease]];
+2
source to share