gistlib
main.swiftfunc getTimeComponents(totalSeconds: Double) -> (hour: Int, minute: Int, second: Int) { let hours = Int(totalSeconds / 3600) let minutes = Int((totalSeconds.truncatingRemainder(dividingBy: 3600)) / 60) let seconds = Int(totalSeconds.truncatingRemainder(dividingBy: 60)) return (hours, minutes, seconds) } // Usage let totalSeconds = 3665.0 let time = getTimeComponents(totalSeconds: totalSeconds) print("Hours: \(time.hour), Minutes: \(time.minute), Seconds: \(time.second)") 498 chars13 lines
func getTimeComponents(totalSeconds: Double) -> (hour: Int, minute: Int, second: Int) { let hours = Int(totalSeconds / 3600) let minutes = Int((totalSeconds.truncatingRemainder(dividingBy: 3600)) / 60) let seconds = Int(totalSeconds.truncatingRemainder(dividingBy: 60)) return (hours, minutes, seconds) } // Usage let totalSeconds = 3665.0 let time = getTimeComponents(totalSeconds: totalSeconds) print("Hours: \(time.hour), Minutes: \(time.minute), Seconds: \(time.second)")
getTimeComponents
gistlibby LogSnag