我想得到两次之间的差异。
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self setCurrentQuestion];
}
-(void)setCurrentQuestion{
dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
[dateFormatter setTimeZone:[NSTimeZone localTimeZone]];
startTime = [dateFormatter stringFromDate:[NSDate date]];
date1 = [dateFormatter dateFromString:startTime];
[self answerTapped];
}
-(void)answerTapped{
endtime = [dateFormatter stringFromDate:[NSDate date]];
date2 = [dateFormatter dateFromString:endtime];
[dateFormatter release];
dateFormatter = nil;
NSTimeInterval * timeDifference =[date2 timeIntervalSinceDate:date1];
}
我正在使用此代码来获取开始时间和结束时间之间的差异,但我得到的错误是“初始化'NSTimeInterval *'(又名'double ')并带有不兼容类型'NSTimeInterval'(又名'double ')的表达式” 在“NSTimeInterval * timeDifference =[date2 timeIntervalSinceDate:date1];” 行。这个错误是什么意思?如何解决这个问题?或者请告诉我如何获得时差?请帮忙。