I want to get weekofYear with date \'2014-12-31\' ,but it always return 1 not 52 here is my code:
NSCalendar *calendar = [NSCalendar currentCalendar];
NSUIntege
Set the minimumDaysInFirstWeek property of the NSCalendar
instance before obtaining the date components.
NSCalendar *calendar = [NSCalendar currentCalendar];
calendar.minimumDaysInFirstWeek = 7; // the week has to be completely within one year
NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit | NSWeekdayCalendarUnit | NSWeekOfMonthCalendarUnit | NSWeekOfYearCalendarUnit;
NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:[NSDate date]];
NSLog(@"%i",dateComponent.weekOfYear); // 52