gpt4 book ai didi

time - Swift 2 从 double 中获取分钟和秒

转载 作者:行者123 更新时间:2023-12-02 09:30:41 26 4
gpt4 key购买 nike

我当前以秒为单位存储时间(例如 70.149 秒)。我如何轻松获得分钟和秒?我的意思是 70.149 秒是 1 分 10 秒。我怎样才能快速轻松地做到这一点?

这是我想要做的事情的示例。

let time:Double = 70.149 //This can be any value
let mins:Int = time.minutes //In this case it would be 1
let secs:Int = time.seconds //And this would be 10

我如何使用 Swift 2 OS X(不是 iOS)来做到这一点

最佳答案

类似这样的事情:

let temp:Int = Int(time + 0.5) // Rounding
let mins:Int = temp / 60
let secs:Int = temp % 60

关于time - Swift 2 从 double 中获取分钟和秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33401388/

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