• 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: 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

  • Follow-Ups:
    • Re: NSCalendar date calculation anomaly
      • From: Scott Ribe <email@hidden>
References: 
 >NSCalendar date calculation anomaly (From: Scott Ribe <email@hidden>)

  • Prev by Date: Re: NSCalendar date calculation anomaly
  • Next by Date: Re: Design for cleaning up Undo for a tree of objects
  • Previous by thread: Re: NSCalendar date calculation anomaly
  • Next by thread: Re: NSCalendar date calculation anomaly
  • Index(es):
    • Date
    • Thread