Getting current year

Just out of curiosity (since this was the first time I had to figure it out in Cocoa) -
Is this the best way to calculate this year?

int thisYear = [[[NSCalendar currentCalendar] components:NSYearCalendarUnit fromDate:[NSDate date]] year]; 

Seems pretty awkward ..

+4
source share
1 answer

Yes, when I need to get components from a date, such as a day, month or year, I use NSDateComponents , the fact is dates are awkward. - There are different calendars, time zones, leap years, etc.

+4
source

Source: https://habr.com/ru/post/1440367/


All Articles