hours
Returns a Duration equal to this Int number of hours.
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
println(26.hours) // 1d 2h
println(0.5.hours) // 30m
// Large values can be converted to an infinite duration
println(10_000_000_000_000.hours) // Infinity
// Double.NaN.hours // will fail with IllegalArgumentException
//sampleEnd
}Returns a Duration equal to this Long number of hours.
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
println(26.hours) // 1d 2h
println(0.5.hours) // 30m
// Large values can be converted to an infinite duration
println(10_000_000_000_000.hours) // Infinity
// Double.NaN.hours // will fail with IllegalArgumentException
//sampleEnd
}Returns a Duration equal to this Double number of hours.
Depending on its magnitude, the value is rounded to an integer number of nanoseconds or milliseconds.
Since Kotlin
1.6Throws
if this Double value is NaN.
Samples
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
println(26.hours) // 1d 2h
println(0.5.hours) // 30m
// Large values can be converted to an infinite duration
println(10_000_000_000_000.hours) // Infinity
// Double.NaN.hours // will fail with IllegalArgumentException
//sampleEnd
}