• 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: Bert Torfs <email@hidden>
  • Date: Thu, 16 Mar 2006 18:18:51 +0100

Thanks,

This solves the problem. However, my Carbon sollution did complete just a day with the current month and year. The cocoa implementation wants the user to enter a complete day.
I'll use this sollution as a second try if the carbon one returns an error.


Bert

On 15 Mar 2006, at 20:21, Nick Zitzmann wrote:


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
References: 
 >Parsing a string into a NSDate (From: Bert Torfs <email@hidden>)
 >Re: Parsing a string into a NSDate (From: Nick Zitzmann <email@hidden>)

  • Prev by Date: Passing a va_list between threads... can it be done?
  • Next by Date: Re: playing swf file
  • Previous by thread: Re: Parsing a string into a NSDate
  • Next by thread: Documentation clarification - NSPredicate LIKE operator?
  • Index(es):
    • Date
    • Thread