//计算相差天数
- (NSInteger)dayIntervalFrom:(NSString *)startDateString to:(NSString *)endDateString {
//时间格式
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
//字符串转时单
NSDate *startDate = [dateFormatter dateFromString:startDateString];
NSDate *endDate = [dateFormatter dateFromString:endDateString];
NSInteger dayInterval = 0;
if (startDate && endDate && [endDate compare:startDate] != NSOrderedAscending) {
//计算天数时间差
NSTimeInterval timeInterval = [endDate timeIntervalSinceDate:startDate];
dayInterval = (NSInteger)(timeInterval / (24 * 3600)) + 1;
}
return dayInterval;
}