toKotlinDuration
Converts java.time.Duration value to kotlin.time.Duration value.
Accuracy of conversion:
Durations in range of ±146 years are converted exactly.
Durations out of that range, but in range of ±146 million years can be rounded to millisecond precision.
Durations greater than that are converted to a positive or negative infinite Duration (see Duration.INFINITE).
Since Kotlin
1.6Samples
import kotlin.test.*
import kotlin.time.*
import kotlin.time.Duration.Companion.days
import kotlin.time.Duration.Companion.hours
import kotlin.time.Duration.Companion.microseconds
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.nanoseconds
import kotlin.time.Duration.Companion.seconds
fun main() {
//sampleStart
val javaMinutes = java.time.Duration.ofMinutes(30)
val kotlinMinutes: Duration = javaMinutes.toKotlinDuration()
println(kotlinMinutes) // 30m
//sampleEnd
}