Re: Odd behavior of [NSDateFormatter dateFromString] with short years?
Re: Odd behavior of [NSDateFormatter dateFromString] with short years?
- Subject: Re: Odd behavior of [NSDateFormatter dateFromString] with short years?
- From: "Hank Heijink (Mailinglists)" <email@hidden>
- Date: Tue, 3 Nov 2009 10:19:02 -0500
On Nov 3, 2009, at 10:06 AM, marc hoffman wrote:
Hi,
im running into some very odd behavior when using a ShortStyle date
formatter for entering dates, and using single vs double digit year
numbers. typing the year as either "2009" or "09" works as expected,
but typing it as "9" not only does *not adjust the century, but also
produces what i'd consider an invalid date. see the following code
and output:
----
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
[dateFormatter setDateStyle:NSDateFormatterShortStyle];
I'm pretty sure NSDateFormatterShortStyle uses 'yy' in its date format
string. I haven't tested this, but that might be the problem. You
could try using your own format string using 'y' instead to see if
that helps. See http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns
and -[NSDateFormatter setDateFormat:].
Good luck,
Hank
_______________________________________________
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