• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Odd behavior of [NSDateFormatter dateFromString] with short years?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Odd behavior of [NSDateFormatter dateFromString] with short years? (From: marc hoffman <email@hidden>)

  • Prev by Date: Odd behavior of [NSDateFormatter dateFromString] with short years?
  • Next by Date: Re: Commandline Tool Help - NSDistantObject and NSConnection
  • Previous by thread: Odd behavior of [NSDateFormatter dateFromString] with short years?
  • Next by thread: priming the NSBeep pump?
  • Index(es):
    • Date
    • Thread