Get the hours, minutes, seconds from seconds iOS Swift 3


If you had only the seconds but you want to display it as hours: minutes: Seconds using the common function.The function will convert your seconds to hour ,minute and seconds.
Code:
    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

    Comments

    Popular posts from this blog

    How to blink a button iOS swift?

    Convert NsNumber, NSDate to String in iOS Swift

    Parse the value from string value iOS swift