一、根据日期获得周
- (NSString*)getInforFromTime:(NSString*)time
{
if (time.length == 0) {
return @"";
}
NSString* winInfor = @"";
NSDateFormatter * dateF= [[NSDateFormatter alloc] init];
dateF.dateFormat = @"yyyy-MM-dd";
NSDate *date = [dateF dateFromString:time];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSInteger unitFlags = NSWeekCalendarUnit|NSWeekdayCalendarUnit;
NSDateComponents *comps = [calendar components:unitFlags fromDate:date];
switch ([comps weekday]) {
case 1:
winInfor = [winInfor stringByAppendingString:@"周日"];
break;
case 2:
winInfor = [winInfor stringByAppendingString:@"周一"];
break;
case 3:
winInfor = [winInfor stringByAppendingString:@"周二"];
break;
case 4:
winInfor = [winInfor stringByAppendingString:@"周三"];
break;
case 5:
winInfor = [winInfor stringByAppendingString:@"周四"];
break;
case 6:
winInfor = [winInfor stringByAppendingString:@"周五"];
break;
case 7:
winInfor = [winInfor stringByAppendingString:@"周六"];
break;
default:
winInfor = [winInfor stringByAppendingString:@"未知"];
break;
}
NSArray* timeArray = [time componentsSeparatedByString:@"-"];
if ([timeArray count] == 3) {
winInfor = [winInfor stringByAppendingFormat:@" %@月%@日", [timeArray objectAtIndex:1], [timeArray objectAtIndex:2]];
}
return winInfor;
}