iOS 计算某个月的天数 计算某天的星期
// 某年某月的天数 - (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; } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。