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

1 Answer

0 votes
object TimeConverter {
  def hhmmsstominutes(hhmmss: String): Double = {
    val time = hhmmss.split(":").map(_.toInt)
    (time(0) * 60) + time(1) + (time(2) / 60.0)
  }

  def main(args: Array[String]): Unit = {
    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 by avibootz

Related questions

1 answer 31 views
1 answer 35 views
1 answer 32 views
1 answer 31 views
1 answer 33 views
...