比较2个时间点 哪个更早
- (NSInteger)compareDate:(NSString*)aDate withDate:(NSString*)bDate{
NSDateFormatter *dateformater = [[NSDateFormatter alloc] init];
[dateformater setDateFormat:@"yyyy-MM-dd"];
NSDate*dta = [[NSDate alloc]init];
NSDate*dtb = [[NSDate alloc]init];
dta = [dateformater dateFromString:aDate];
dtb = [dateformater dateFromString:bDate];
NSComparisonResult result = [dta compare:dtb];
if (result == NSOrderedDescending) {
return 1;
} else if(result == NSOrderedAscending) {
return -1;
} else {
//刚好时间一样.
return 0;
}
}