Swift - Integer conversion to Hours/Minutes/Seconds

后端 未结 23 1243
無奈伤痛
無奈伤痛 2020-11-28 01:47

I have a (somewhat?) basic question regarding time conversions in Swift.

I have an integer that I would like converted into Hours / Minutes / Second

23条回答
  •  时光说笑
    2020-11-28 02:21

    I went ahead and created a closure for this (in Swift 3).

    let (m, s) = { (secs: Int) -> (Int, Int) in
            return ((secs % 3600) / 60, (secs % 3600) % 60) }(299)
    

    This will give m = 4 and s = 59. So you can format that as you wish. You may of course want to add hours as well, if not more information.

提交回复
热议问题