提问人:Pietro di Caprio 提问时间:11/18/2014 最后编辑:rmaddyPietro di Caprio 更新时间:11/18/2014 访问量:314
Objective-C Xcode - if 语句“预期表达式”
Objective-C Xcode - if statement "Expected expression"
问:
我必须检查 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)
有人可以帮我吗?
问候。
答: 暂无答案
下一个:启动多个进程并异步重定向输出
评论
NSDateComponents
NSCalendar
;