NSDateFormatter honours user's 12/24 hour setting even when overridden in code

Originator:amorya
Number:rdar://8988715 Date Originated:11-Feb-2011 03:04 PM
Status:Open Resolved:
Product:iPhone SDK Product Version:4.2.1
Classification:Other Bug Reproducible:Always
 
11-Feb-2011 03:04 PM Amy Worrall:
Summary:
When the user has set their 12/24 hour clock setting to the opposite of their region's default, NSDateFormatter refuses to parse dates in the other setting, even when a specific date format is specified by the developer.

Steps to Reproduce:
1. Set iPhone region format to United Kingdom
2. Set iPhone 12/24 hour setting to 12 hour clock
3. Run the following code:

	NSString *dateString = @"2031-01-01 22:20:00";
	
	NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
	[dateFormatter setTimeZone: [NSTimeZone timeZoneWithAbbreviation:@"GMT"]];
	[dateFormatter setDateFormat: @"yyyy-MM-dd HH:mm:ss"];  
	
	NSDate *dateOut = [dateFormatter dateFromString:dateString];
	
	NSLog(@"Date: %@", dateOut);


Expected Results:
Logged: "Date: 2031-01-01 22:20:00 +0000"

Actual Results:
Logged: "Date: (null)"

Regression:

Notes:

Comments

Apple responded, and claimed it works as designed. I hence requested the documentation to be changed: see bug 9080156 http://openradar.appspot.com/radar?id=1129405

A workaround is to explicitly set a region on the date formatter before using it to parse a string.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!