Get the hours, minutes, seconds from seconds iOS Swift 3
Code:
func secondsToHoursMinutesSeconds (seconds : Int) -> (Int, Int, Int) {
func secondsToHoursMinutesSeconds (seconds : Int) -> (Int, Int, Int) {
return (seconds / 3600, (seconds % 3600) / 60, (seconds % 3600) % 60)
}
The above function will be called by the below code.the below code will display the timer as mm: ss
let time = secondsToHoursMinutesSeconds(seconds: Int(seconds))
textView.text = String(format: "%02d:%02d",time.1,time.2)
You can get the array with three values.You can get the values by index like time.1, time.2 and time.3
You can get the array with three values.You can get the values by index like time.1, time.2 and time.3
Comments
Post a Comment