首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >我想在swift 5中用事件时间(来自我的json api)减去当前时间

我想在swift 5中用事件时间(来自我的json api)减去当前时间
EN

Stack Overflow用户
提问于 2020-12-21 14:53:57
回答 1查看 55关注 0票数 0

我有一个api,它给我一个事件时间,如电影时间,我想在我的应用程序中添加倒计时时间,告诉我还有多少时间开始一部电影。

EN

回答 1

Stack Overflow用户

发布于 2020-12-23 02:59:37

您的代码不会显示,但我希望这会有所帮助。

代码语言:javascript
运行
复制
// 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()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65388610

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档