• 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
Re: NSCalendar date calculation anomaly
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: Re: Creating temporary NSManagedObjects
  • Next by Date: Re: white screen windows at first
  • Previous by thread: Re: NSCalendar date calculation anomaly
  • Next by thread: Re: NSCalendar date calculation anomaly
  • Index(es):
    • Date
    • Thread