How to convert an NSTimeInterval (seconds) into minutes

前端 未结 12 962
轮回少年
轮回少年 2020-11-28 01:27

I\'ve got an amount of seconds that passed from a certain event. It\'s stored in a NSTimeInterval data type.

I want to convert it into

12条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-28 01:43

    Here's a Swift version:

    func durationsBySecond(seconds s: Int) -> (days:Int,hours:Int,minutes:Int,seconds:Int) {
        return (s / (24 * 3600),(s % (24 * 3600)) / 3600, s % 3600 / 60, s % 60)
    }
    

    Can be used like this:

    let (d,h,m,s) = durationsBySecond(seconds: duration)
    println("time left: \(d) days \(h) hours \(m) minutes \(s) seconds")
    

提交回复
热议问题