如何解决想在swift 5中用事件时间来自我的json api减去当前时间
我有一个 api,它为我提供电影时间等事件时间我想在我的应用程序中添加一个倒计时时间,告诉我还有多少时间可以开始看电影。
解决方法
您的代码未显示,但我希望这会有所帮助。
// use repeating scheduledTimer(withTimeInterval:repeats:block:) method for the Timer.
// Initialize the timer and save in the property for invalidating
private let step: Double = 1.0
private var timer: Timer?
private func initTimer() {
let action: (Timer)-> Void = { [weak self] timer in
guard let StrongSelf = self else {
return
}
}
}
timer = Timer.scheduledTimer(withTimeInterval: step,repeats: true,block: action)
private func deinitTimer() {
timer?,invalidate()
timer = nil
}
// To Display
func timeString(from timeInterval: TimeInterval) -> String {
let seconds = Int(timeInterval.turncatingRemainder(dividingBy: 60))
let minutes = Int(timeInterval.turncatingRemainder(dividingBy: 60 * 60) / 60)
let hours = Int(timeInterval / 3600)
return String(format: "%.value:%.value:%.value",hours,minutes,seconds
}
// Pause & Resume
stopwatch.toggle()
//Reset
stopwatch.stop()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。