gpt4 book ai didi

ios - 秒表 - 从 UIDatePicker 设置开始日期

转载 作者:行者123 更新时间:2023-11-29 12:44:59 26 4
gpt4 key购买 nike

我有一个简单的秒表,可以显示自按下开始按钮以来耗时(以秒为单位)。我需要的是从日期选择器设置开始时间。

如何获取“NSTimeInterval 时间;”等于我的日期选择器?还是我需要做其他事情来设置用户的时间?

@实现 View Controller {

bool start;

// Gets time when the button is pressed.
NSTimeInterval time;

  • (无效)viewDidLoad{[ super viewDidLoad];

    self.display.text = @"0:00";

    开始=假;

-(无效)更新{

if (start == false) {

return;

}

NSTimeInterval currentTime = [NSDate timeIntervalSinceReferenceDate];
NSTimeInterval elapsedTime = currentTime - time;

// minutes.
int minutes = (int)(elapsedTime / 60.0);

// seconds.
int seconds = (int)(elapsedTime = elapsedTime - (minutes * 60));


self.display.text = [NSString stringWithFormat:@"%u:%02u", minutes, seconds];

[self performSelector:@selector(update) withObject:self afterDelay:0.1];

最佳答案

您可以使用:

NSTimeInterval timePicker = [[self.datePicker date] timeIntervalSinceReferenceDate];
NSTimeInterval currentTime = [[NSDate date] timeIntervalSinceReferenceDate];
NSTimeInterval elapsedTime = currentTime - timePicker;
// minutes.
int minutes = (int)(elapsedTime / 60.0);

// seconds.
int seconds = (int)(elapsedTime = elapsedTime - (minutes * 60));

关于ios - 秒表 - 从 UIDatePicker 设置开始日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23879136/

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