Hi all,
I'm trying to return the 4 digit year from any given date as an integer. I'm not strong with the NSCalendar or NSDate functions, but have tried using them with components from date and date formatters with no success.
Thanks.
Hi all,
I'm trying to return the 4 digit year from any given date as an integer. I'm not strong with the NSCalendar or NSDate functions, but have tried using them with components from date and date formatters with no success.
Thanks.
From NSCalendar
docs:
unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
NSDate *date = [NSDate date];
NSDateComponents *comps = [gregorian components:unitFlags fromDate:date];
Then you can get the year by doing:
NSInteger year = [comps year];