Re: NSCalendar date calculation anomaly
Re: NSCalendar date calculation anomaly
- Subject: Re: NSCalendar date calculation anomaly
- From: Kyle Sluder <email@hidden>
- Date: Tue, 27 Apr 2010 21:37:01 -0700
On Tue, Apr 27, 2010 at 8:45 PM, Scott Ribe <email@hidden> wrote:
> NSDate * cd = [[NSCalendar currentCalendar] dateByAddingComponents: dc toDate: [NSDate dateWithString: @"2001-01-01"] options: 0];
This is a wrong. You don't need to go from a string to a date here.
You are violating the requirement laid out in the documentation: "You
must specify all fields of the format string, including the time zone
offset, which must have a plus or minus sign prefix." And if you ever
want to convert a string to a date, you should be using an
NSDateFormatter anyway.
So don't do this. Just use -initWithTimeIntervalSinceReferenceDate:
instead. The reference date is conveniently 2001-01-01 00:00:00 +0000.
--Kyle Sluder
_______________________________________________
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