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 protected])
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]