Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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..

like image 852
Jay Avatar asked Oct 07 '22 07:10

Jay


1 Answers

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.

like image 197
Daniel Avatar answered Oct 10 '22 04:10

Daniel