Re: Parsing a string into a NSDate
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