toIsoString

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
fun toIsoString(): String

Returns an ISO-8601 based string representation of this duration.

The returned value is presented in the format PThHmMs.fS, where h, m, s are the integer components of this duration (see toComponents) and f is a fractional part of second. Depending on the roundness of the value the fractional part can be formatted with either 0, 3, 6, or 9 decimal digits.

If the hours component absolute value of this duration is greater than Int.MAX_VALUE, it is replaced with Int.MAX_VALUE, so the infinite duration is formatted as `"PT2147483647H".

Negative durations are indicated with the sign - in the beginning of the returned string, for example, "-PT5M30S".

import kotlin.time.*

fun main(args: Array<String>) {
//sampleStart
println(25.nanoseconds.toIsoString()) // PT0.000000025S
println(120.3.milliseconds.toIsoString()) // PT0.120300S
println(30.5.seconds.toIsoString()) // PT30.500S
println(30.5.minutes.toIsoString()) // PT30M30S
println(86420.seconds.toIsoString()) // PT24H0M20S
println(2.days.toIsoString()) // PT48H
println(Duration.ZERO.toIsoString()) // PT0S
println(Duration.INFINITE.toIsoString()) // PT2147483647H
//sampleEnd
}

© 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.time/-duration/to-iso-string.html