我需要计算给定日期的工作日,但是,根据日历,一周可以在星期一和星期日的某个地方出现
所以我想设置它,从星期一开始,使用
[[NSCalendar currentCalendar] setFirstWeekday:2];
但是,计算结果是一样的
{
[[NSCalendar currentCalendar] setFirstWeekday:1];
NSDateComponents *weekdayComponents = [[NSCalendar currentCalendar] components:(NSDayCalendarUnit | NSWeekdayCalendarUnit) fromDate:date];
NSInteger weekday = [weekdayComponents weekday] - 1;
NSLog(@"%d", weekday);
}
{
[[NSCalendar currentCalendar] setFirstWeekday:2];
NSDateComponents *weekdayComponents = [[NSCalendar currentCalendar] components:(NSDayCalendarUnit | NSWeekdayCalendarUnit) fromDate:date];
NSInteger weekday = [weekdayComponents weekday] - 1;
NSLog(@"%d", weekday);
}
返回相同的数字,但为什么呢?