注:返回的是数字1,2,。。。
+ (NSInteger)getWeekDayFordate
{
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *comps = [[NSDateComponents alloc] init];
NSInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit |
NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
NSDate *now = [NSDate date];
// 在真机上需要设置区域,才能正确获取本地日期,天朝代码:zh_CN
calendar.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
comps = [calendar components:unitFlags fromDate:now];
return [comps weekday] - 1;
}