How to convert an NSTimeInterval (seconds) into minutes

前端 未结 12 959
轮回少年
轮回少年 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:40

    How I did this in Swift (including the string formatting to show it as "01:23"):

    let totalSeconds: Double = someTimeInterval
    let minutes = Int(floor(totalSeconds / 60))
    let seconds = Int(round(totalSeconds % 60))        
    let timeString = String(format: "%02d:%02d", minutes, seconds)
    NSLog(timeString)
    

提交回复
热议问题