// 某年某月的天数 - (NSInteger)dayCount:(NSInteger)years { NSInteger count = 0; for (int i = 1; i <= 12; i++) { if (2 == i) { if((years % 4 == 0 && years % 100!=0) || years % 400 == 0) //是闰年 { count = 29; } else { count = 28; } }else if (4 == i || 6 == i || 9 == i || 11 == i){ count = 30; }else{ count = 31; } } return count; }
// 某天的星期 - (NSString * )whichWeek:(NSString *)dateStr { NSCalendar *calendar = [NSCalendar currentCalendar]; NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init]; [inputFormatter setDateFormat:@"yyyy-MM-dd"]; NSDate* inputDate = [inputFormatter dateFromString:dateStr]; NSDateComponents *dateComps = [calendar components:NSCalendarUnitWeekday fromDate:inputDate]; NSInteger weekDay = dateComps.weekday; switch (weekDay) { case 1: return @"星期日"; break; case 2: return @"星期一"; break; case 3: return @"星期二"; break; case 4: return @"星期三"; break; case 5: return @"星期四"; break; case 6: return @"星期五"; break; case 7: return @"星期六"; break; default: return @""; break; } }