#计算接口数据返回耗时:
undefined
NSDate *d1 = [NSDate date];
[self.manager requestJSONDataWithMethod:@"post" path:@"data/search/xxx.do" parameters:params success:^(id responseObject) {
NSDate *d2 = [NSDate date];
NSTimeInterval time = [d2 timeIntervalSinceDate:d1];
NSLog(@"liqi==searchTimeCost====%f",time);
//简单计算耗时
successBlock([self parseResponDatas:responseObject]);
} failure:^(NSError *error) {
failureBlock(error);
}
注:NSTimeInterval本身是以秒为单位的值。
#计算任意两个时间点的时间差:
undefined
- (NSTimeInterval)pleaseInsertStarTime:(NSString *)starTime andInsertEndTime:(NSString *)endTime{
NSDateFormatter* formater = [[NSDateFormatter alloc] init];
[formater setDateFormat:@"mm:ss"];//根据自己的需求定义格式
NSDate* startDate = [formater dateFromString:starTime];
NSDate* endDate = [formater dateFromString:endTime];
NSTimeInterval time = [endDate timeIntervalSinceDate:startDate];
return time;
}
作者:Silence_广