[objective-c]2つの日付の差を日数で出す
2つの日付の差を日数で出す
int dayCount = [self getDaysCountByTwoDateString:@"2014-04-01" endDateString:@"2014-04-04"]; -(int)getDaysCountByTwoDateString:(NSString*)startDateString endDateString:(NSString*)endDateString { NSDateFormatter *inputDateFormatter = [[NSDateFormatter alloc] init]; [inputDateFormatter setDateFormat:@"yyyy-MM-dd"]; NSDate *startInputDate = [inputDateFormatter dateFromString:startDateString]; NSDate *endInputDate = [inputDateFormatter dateFromString:endDateString]; float tmp= [endInputDate timeIntervalSinceDate:startInputDate]; int day=(int)( tmp / (3600.0*24.0) ); return day; }