• 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
Strange results with NSDateComponents vs NSCalendarDate
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Strange results with NSDateComponents vs NSCalendarDate
      • From: Deborah Goldsmith <email@hidden>
  • Prev by Date: Re: Binding NSTextField to an Unsigned int
  • Next by Date: Re: Binding NSTextField to an Unsigned int
  • Previous by thread: Re: Binding NSTextField to an Unsigned int
  • Next by thread: Re: Strange results with NSDateComponents vs NSCalendarDate
  • Index(es):
    • Date
    • Thread