• 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: Parsing a string into a NSDate
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Parsing a string into a NSDate


  • Subject: Re: Parsing a string into a NSDate
  • From: Nick Zitzmann <email@hidden>
  • Date: Wed, 15 Mar 2006 12:21:55 -0700


On Mar 15, 2006, at 12:01 PM, Bert Torfs wrote:

NSString* shortDateFormat;
shortDateFormat = [[NSUserDefaults standardUserDefaults] objectForKey:NSShortDateFormatString]; // "%e/%m/%y"
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:shortDateFormat];
NSDate* ObjCDate = [dateFormatter dateFromString:inStringDate]; // inStringDate = "15/03/06" result = 01/03/06 (????????)


The problem with this code is that todays date ("15/03/06") is translated into 01/03/06 - the day part being wrong. What did I do wrong?

You first need to set the date formatter behavior to 10.4 behavior, then set the date style to the short style, and then set the time style to no style. Then -dateFromString: ought to work as expected.


Nick Zitzmann
<http://www.chronosnet.com/>


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Parsing a string into a NSDate
      • From: Bert Torfs <email@hidden>
References: 
 >Parsing a string into a NSDate (From: Bert Torfs <email@hidden>)

  • Prev by Date: Re: Getting a bullet into a NSString
  • Next by Date: Re: Help on NSToolbar
  • Previous by thread: Parsing a string into a NSDate
  • Next by thread: Re: Parsing a string into a NSDate
  • Index(es):
    • Date
    • Thread