NSDateComponents *_comps = [[NSDateComponents alloc] init];
[_comps setDay:19];
[_comps setMonth:4];
[_comps setYear:2016];
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDate *_date = [gregorian dateFromComponents:_comps];
NSDateComponents *weekdayComponents =
[gregorian components:NSCalendarUnitWeekday fromDate:_date];
NSInteger _weekday = [weekdayComponents weekday];
NSLog(@"_weekday:%ld",_weekday);
输出结果为“1--7”的值,1代表星期日。
网友评论