Strange results with NSDateComponents vs NSCalendarDate
Strange results with NSDateComponents vs NSCalendarDate
- Subject: Strange results with NSDateComponents vs NSCalendarDate
- From: "Sean McBride" <email@hidden>
- Date: Sat, 3 Feb 2007 14:11:11 -0500
Hi all,
I have been switching from NSCalendarDate to NSDateComponents as a first
step to supporting non-Gregorian calendars. But I don't understand this
behaviour:
NSCalendar* cal = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar]];
NSDateComponents* comps = [[NSDateComponents alloc] init];
[comps setDay:27];
[comps setMonth:1];
[comps setYear:100];
NSDate* date = [cal dateFromComponents:comps];
NSLog (@"date %@", date);
NSCalendarDate* calDate = [NSCalendarDate dateWithYear:100
month:1 day:27 hour:0 minute:0 second:0 timeZone:nil];
NSLog (@"calDate %@", calDate);
Outputs:
date 100-01-24 23:00:00 -0500
calDate 100-01-27 00:00:00 -0500
Why do I get the wrong date with NSDateComponents? The day should be 27
not 24.
Thanks,
Sean
--
1908's Model T Ford: 25 miles per gallon. Today's Ford Expedition: 15.5 mpg.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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