iOS根据日期计算星期

NSDate *inputDate =[CMCore dateFromString:date format:kDateFormatYMD];    NSCalendar *calendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];  
NSDateComponents *comps = [[NSDateComponents alloc] init];    
NSInteger unitFlags =NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit|NSWeekdayCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit;    comps = [calendar components:unitFlags fromDate:inputDate];    
NSString *week = nil;   
switch ([comps weekday]) {        
case 1:           
week = @"星期日";            
break;       
case 2:           
week = @"星期一";           
break;       
case 3:           
week = @"星期二";            
break;        
case 4:           
week = @"星期三";          
break;        
case 5:           
week = @"星期四";           
break;        
case 6:           
week = @"星期五";           
break;        
case 7:          
week = @"星期六";            
break;                   
default:            
break;
  }

你可能感兴趣的:(iOS根据日期计算星期)