NSArray *timeArray = [device_data sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat: @"yyyy-MM-dd HH:mm:ss"];
NSDate *date1= [dateFormatter dateFromString:obj1[@"time"]?:@""];
NSDate *date2= [dateFormatter dateFromString:obj2[@"time"]?:@""];
if (date1 == [date1 earlierDate: date2]) {
//降序
return NSOrderedDescending;
}else if (date1 == [date1 laterDate: date2]) {
//升序
return NSOrderedAscending;
}else{
return NSOrderedSame;
}
}];
网友评论