gpt4 book ai didi

ios - 在日期之间执行操作数

转载 作者:行者123 更新时间:2023-11-30 12:08:21 25 4
gpt4 key购买 nike

我正在做一个秒表,并且需要在事件持续到结束时显示计时器。承认事件于晚上 8 点开始,当前日期为晚上 9.30,秒表显示 01:30:00,并将继续滴答作响,直到 end_time 到达。这是我的代码,我需要一种方法来为 currentTime 提供 currentDate-start_time 的值

var currentTime = 0

func printTime() {
let formatter = DateFormatter()
formatter.dateFormat = "dd/MM/yyyy"
let start_time = self.eventArray[self.clubId!]?.start_time
let end_time = self.eventArray[self.clubId!]?.end_time
self.currentTime = currentDate - start_time


if(currentDate?.compare(start_time!) == .orderedAscending && currentDate?.compare(end_time!) == .orderedAscending)
{
if(timer != nil)
{
timer?.invalidate()
timer = nil
}else
{
timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true, block: { _ in
self.currentTime += 1
let hoursPortion = String(format: "%02d", self.currentTime / 60)
let minutesPortion = String(format: "%02d", self.currentTime / 60)
let secondsPortion = String(format: "%02d", self.currentTime % 60)
self.sinceBandeauLabel.text = "\(hoursPortion):\(minutesPortion):\(secondsPortion)"
})

}

}

最佳答案

如果start_timeDate,那么您可以使用currentDate.timeIntervalSince(start_time)

关于ios - 在日期之间执行操作数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46401817/

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