Jay
Jay

Reputation: 6638

Getting the current year

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

Answers (1)

Daniel
Daniel

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

Related Questions