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

1 Answer

0 votes
fun hhmmsstominutes(hhmmss: String): Double {
    val time = hhmmss.split(":").map { it.toInt() }
    
    return (time[0] * 60) + time[1] + (time[2] / 60.0)
}

fun main() {
    println(hhmmsstominutes("2:30:00"))
    println(hhmmsstominutes("2:35:30"))
    println(hhmmsstominutes("5:00:45"))
}

   
      
/*
run:

150.0
155.5
300.75
  
*/

 



answered Apr 17, 2025 by avibootz

Related questions

1 answer 87 views
1 answer 84 views
1 answer 90 views
1 answer 105 views
1 answer 96 views
1 answer 178 views
1 answer 115 views
...