我正在尝试制作一个时间戳应用程序,你可以通过一个按钮捕捉时间。
当按下按钮时,它会打印出当前时间
00:00:00
.
当第二次按下按钮时,它会再次打印出当前时间(即
00:00:15
).
然后我想让它计算两个时间戳之间的时间差(10秒)。
我是objective-c的新手,我已经处理这个小问题好几个小时了。如果有一个指向正确方向的指针就好了。
我在
timeIntervalSinceDate
。这是代码:
- (IBAction)checkButton:(id)sender {
if (buttonPress) {
self.checkInStamp = [NSDate date];
NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init];
[timeFormatter setTimeStyle:NSDateFormatterMediumStyle];
checkInTime.text = [timeFormatter stringFromDate:checkInStamp];
buttonPress = false;
}
else {
self.checkOutStamp = [NSDate date];
NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init];
[timeFormatter setTimeStyle:NSDateFormatterMediumStyle];
checkOutTime.text = [timeFormatter stringFromDate:checkOutStamp];
NSTimeInterval timeDifference = [checkOutStamp timeIntervalSinceDate:checkInStamp];
totalDuration.text = @"%d", timeDifference; //<-This gives "Expression result unused on build"
}
}
谢谢你的帮助!