How to convert hh:mm:ss to minutes in Swift

1 Answer

0 votes
import Foundation

func hhmmsstominutes(_ hhmmss: String) -> Double {
    let time = hhmmss.split(separator: ":").compactMap { Double($0) }
    
    return (time[0] * 60) + time[1] + (time[2] / 60)
}

print(hhmmsstominutes("2:30:00"))
print(hhmmsstominutes("2:35:30"))
print(hhmmsstominutes("5:00:45"))



/*
run:

150.0
155.5
300.75

*/

 



answered Apr 17, 2025 by avibootz

Related questions

1 answer 79 views
1 answer 95 views
1 answer 83 views
1 answer 92 views
1 answer 85 views
1 answer 153 views
1 answer 95 views
...