iOS开发 根据日期计算是星期几

来源:互联网 发布:算法第四版英文版pdf 编辑:程序博客网 时间:2024/05/16 01:04
NSDateComponents *_comps = [[NSDateComponents alloc] init];
    [_comps setDay:23];
    [_comps setMonth:3];
    [_comps setYear:2014];
    NSCalendar *gregorian = [[NSCalendar alloc]
                             initWithCalendarIdentifier:NSGregorianCalendar];
    NSDate *_date = [gregorian dateFromComponents:_comps];
    NSDateComponents *weekdayComponents =
    [gregorian components:NSWeekdayCalendarUnit fromDate:_date];
    int _weekday = [weekdayComponents weekday];
    NSLog(@"_weekday::%d",_weekday); 
0 0
原创粉丝点击