-[NSDateFormatter dateFormatFromTemplate:options:locale:] does not work as expected
-[NSDateFormatter dateFormatFromTemplate:options:locale:] does not work as expected
- Subject: -[NSDateFormatter dateFormatFromTemplate:options:locale:] does not work as expected
- From: Kai Brüning <email@hidden>
- Date: Mon, 29 Mar 2010 11:42:57 +0200
Hi,
I am having problems using -[NSDateFormatter dateFormatFromTemplate:options:locale:] (new in 10.6.). It’s a great API which makes world-savvy custom date formats possible.
Unfortunately it does not seem to work. Examples of wrong results are:
- Hour format templates like "h a" (12 Hour with AM/PM) are converted to format "H" (24 Hour) under US locale. Other combinations ("ha ", "h", "H" under US or German locale) also always return "H".
- The template "EEyMd" is converted to format "EE, yyyy-M-d" under German locale. This is completely wrong, expected would be "EE, d.M.yyyy".
I filed a bug under rdar://7803429.
Does anybody have similar experiences with this method? Any work around to make it work?
- Kai
---------------------
Test code:
The following code:
NSLocale* usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en-US"];
NSLocale* germanLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"de-DE"];
NSString* format = [NSDateFormatter dateFormatFromTemplate:@"h a" options:0 locale:usLocale];
NSLog (@"Template “h a” with US local results in “%@”", format);
format = [NSDateFormatter dateFormatFromTemplate:@"H" options:0 locale:usLocale];
NSLog (@"Template “H” with US local results in “%@”", format);
format = [NSDateFormatter dateFormatFromTemplate:@"h" options:0 locale:usLocale];
NSLog (@"Template “h” with US local results in “%@”", format);
format = [NSDateFormatter dateFormatFromTemplate:@"h a" options:0 locale:germanLocale];
NSLog (@"Template “h a” with German local results in “%@”", format);
format = [NSDateFormatter dateFormatFromTemplate:@"H" options:0 locale:germanLocale];
NSLog (@"Template “H” with German local results in “%@”", format);
format = [NSDateFormatter dateFormatFromTemplate:@"EEyMd" options:0 locale:germanLocale];
NSLog (@"Template “EEyMd” with German local results in “%@”", format);
gives me this output:
Template “h a” with US local results in “H”
Template “H” with US local results in “H”
Template “h” with US local results in “H”
Template “h a” with German local results in “H”
Template “H” with German local results in “H”
Template “EEyMd” with German local results in “EE, yyyy-M-d”
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden