Reputation: 6638
Just out of curiosity (as this was the first time I've ever needed to calculate it in Cocoa) -
Is this really the most concise way to calculate the current year?
int thisYear = [[[NSCalendar currentCalendar]
components:NSYearCalendarUnit fromDate:[NSDate date]]
year];
Seems pretty clumsy..
Upvotes: 5
Views: 2172
Reputation: 23359
Yes, when I need to get components from a date like the day, month or year, I use NSDateComponents
, fact is dates are clumsy - There are different calendars, time zones, leap years etc.
Upvotes: 4