Re: NSCalendar date calculation anomaly
Re: NSCalendar date calculation anomaly
- Subject: Re: NSCalendar date calculation anomaly
- From: Greg Guerin <email@hidden>
- Date: Wed, 28 Apr 2010 11:25:51 -0700
Scott Ribe wrote:
> NSDate * cd = [[NSCalendar currentCalendar]
dateByAddingComponents: dc toDate: [NSDate dateWithString:
@"2001-01-01"] options: 0];
I think the dateWithString: is wrong. From the NSDate reference:
"You must specify all fields of the format string, including the time
zone offset, which must have a plus or minus sign prefix."
Refactored code fragments:
NSDate * refDate1 = [NSDate dateWithString: @"2001-01-01"];
NSDate * refDate2 = [NSDate dateWithString: @"2001-01-01 00:00:00
+0000"];
NSLog( @"refDate1: %@", refDate1 );
NSLog( @"refDate2: %@", refDate2 );
...
NSDate * cd = [[NSCalendar currentCalendar] dateByAddingComponents: dc
toDate: refDate1 options: 0]; // should be same as original
...
NSDate * cd = [[NSCalendar currentCalendar] dateByAddingComponents: dc
toDate: refDate2 options: 0];
-- GG
_______________________________________________
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