标签:
1 - (NSInteger)getWeekDataWithYear:(NSString *)year month:(NSString *)month day:(NSString *)day{ 2 3 // 创建并设置NSDateComponents,它可以根据制定的时间生成对应的Date,同时需要根据相应的Calender 4 NSDateComponents *comps = [[NSDateComponents alloc] init]; 5 [comps setDay:[day integerValue]]; 6 [comps setMonth:[month integerValue]]; 7 [comps setYear:[year integerValue]]; 8 // 创建Calender,格林威治时间,周日weekday是1以此类推 9 NSCalendar *gregorian1 = [[NSCalendar alloc] 10 initWithCalendarIdentifier:NSGregorianCalendar]; 11 NSDate *date = [gregorian1 dateFromComponents:comps]; 12 NSDateComponents *weekdayComponents = 13 [gregorian1 components:NSWeekdayCalendarUnit fromDate:date]; 14 15 NSInteger weekday = [weekdayComponents weekday]; 16 17 return weekday; 18 19 }
标签:
原文地址:http://www.cnblogs.com/Mike-Fighting/p/5060537.html