NSDate
I'm pretty sure this is not the official way to do it, but an easy way to extract the year-month-date information from an NSDate instance is to do
componentsSeparatedByString:@" "
on the description. Also, notice that constructing an NSDate object from a string requires a complete specification---including the time zone!
And at first I thought, there seems to be a bug in Apple's implementation of the
dateWithString
method. We specified January 1, but the resulting NSDate is one day (and one year) earlier. The answer lies in the time zone. Cocoa has converted my GMT time in constructing the NSDate to the current time zone where I am, even correcting for daylight savings time on the appropriate dates.