I'm trying to parse dates using the user's date preferences
[NSDateFormatter setDefaultFormatterBehavior:NSDateFormatterBehavior10_4];
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateStyle:NSDateFormatterShortStyle];
NSDate *date = [ dateFormatter dateFromString:@"7/4/2008" ];
NSLog(@"string from date %@: %@ for locale %@", date, [dateFormatter stringFromDate:date], [[dateFormatter locale] localeIdentifier]);
When I set my region (in the International system preferences) to be United States, it prints:
2008-08-14 20:20:31.117 Date Difference17226:10b string from date 2008-07-04 00:00:00 -0400: 7/4/08 for locale en_US
And when my region is United Kingdom, it prints:
2008-08-14 20:19:23.441 Date Difference17199:10b string from date 2008-04-07 00:00:00 -0400: 07/04/2008 for locale en_GB
It looks like the NSDateFormatter is insensitive to the change of regions. Notice that the raw printing of the date is properly switching with the region, though.
What do I have to do to get the NSDateFormatter to respect the region setting?