Parsing a Duration String in Kotlin

后端 未结 3 1881
终归单人心
终归单人心 2021-01-06 10:06

I\'m working on a Android application and I need to parse a duration string of this form \"00:00:00.000\" (Ex: \"00:00:38.47\" or \"00:03:27.11\").

My final goal is

3条回答
  •  失恋的感觉
    2021-01-06 10:17

      val time = LocalTime.parse("00:01:08.83", DateTimeFormatter.ofPattern("HH:mm:ss.SS"))
    
      println(time.toSecondOfDay())
      println(time.toNanoOfDay())
      println(time.toNanoOfDay().toFloat() / 1_000_000_000)
    

    Output:

    68
    68830000000
    68.83
    

提交回复
热议问题