代码 直接 用就行.
唯有一个要说一下的是.
week 取值的时候是从1开始的,
所以要在数组的第一位加上一个空对像.
+ (NSString *)getWeek:(NSDate *)date{
NSArray * arrWeek=[NSArrayarrayWithObjects:[NSNullnull],@"星期日",@"星期一",@"星期二",@"星期三",@"星期四",@"星期五",@"星期六",nil];
NSCalendar *calendar = [[NSCalendaralloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *comps = [[NSDateComponentsalloc] init];
NSInteger unitFlags =NSYearCalendarUnit |
NSMonthCalendarUnit |
NSDayCalendarUnit |
NSWeekdayCalendarUnit |
NSHourCalendarUnit |
NSMinuteCalendarUnit |
NSSecondCalendarUnit;
comps = [calendar components:unitFlagsfromDate:date];
NSInteger week = [compsweekday];
// int year=[comps year];
// int month = [comps month];
// int day = [comps day];
return [arrWeekobjectAtIndex:week];
// m_labDate.text=[NSString stringWithFormat:@"%d年%d月",year,month];
// m_labToday.text=[NSString stringWithFormat:@"%d",day];
// m_labWeek.text=[NSString stringWithFormat:@"%@",[arrWeek objectAtIndex:week]];
}