gpt4 book ai didi

ios - 秒表和计时器

转载 作者:行者123 更新时间:2023-11-28 22:41:45 25 4
gpt4 key购买 nike

我想使用 NSDate 和 NSTimer 来检索我按下开始按钮和停止按钮之间耗时,并以秒为单位显示时间。然后我想用时间来计算一下。我知道如何获得时间,但它的格式总是像这样 2013-01-15 14:01:55.369。我如何从另一个中减去一个时间以获得秒数。我不确定如何使用 NDDate 和 NSTimer。这应该很容易,但我有点被困在这里。

最佳答案

//Make two properties `NSDate *startDate, *endDate`

//in the action method of start Button
startDate=[NSDate date];

//in the action method of stop Button
stopDate=[NSDate date];
long elapsedSeconds=[stopDate timeIntervalSinceDate:startDate];
NSLog(@"Elaped seconds:%ld seconds",elapsedSeconds);

请查看我的project对于秒表之类的东西,这对你来说可能会派上用场

检查这段代码,大部分需求都在这里解决。

关于ios - 秒表和计时器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14338491/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com