iOS中根据当前日期判断是星期几

NSCalendar *calendar = [[NSCalendaralloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];

NSDate *now = [NSDate date];

NSDateComponents *comps = [[NSDateComponentsalloc] init];

NSInteger unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitWeekday |

NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;

calendar.locale = [[NSLocalealloc] initWithLocaleIdentifier:@"zh_CN"];

comps = [calendar components:unitFlags fromDate:now];

long week = [comps weekday];

NSLog(@"week=============%ld",week);

你可能感兴趣的:(iOS中根据当前日期判断是星期几)