Objective-C Xcode - if语句"预期表达式"

时间:2014-11-17 18:16:19

标签: objective-c

我必须检查2次之间的间隔是否> 0然后设置标签的文本,但当我使用if语句时,我得到“预期表达式”..

NSDate * now = [NSDate date];
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setDateFormat:@"HH:mm:ss"];
NSString *newDateString = [outputFormatter stringFromDate:now];

NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"HH:mm:ss"];
NSDate *date1 = [df dateFromString:newDateString];
NSDate *date2 = [df dateFromString:@"15:00:00"];
NSTimeInterval interval = [date2 timeIntervalSinceDate:date1];
int hours = (int)interval / 3600; // integer division to get the hours part
int minutes = (interval - (hours*3600)) / 60; // interval minus hours part (in seconds) divided by 60 yields minutes
int seconds = interval - ((hours*3600)+(minutes*60)) ;
NSString *timeDiff = [NSString stringWithFormat:@"%02d | %02d | %02d", hours, minutes, seconds];

if (interval < 0)
{
self.before3.text = timeDiff;
}

错误发生在if (interval < 0)

有人能帮助我吗?

问候。

0 个答案:

没有答案