microseconds
Версия Kotlin: 1.6
val Int.microseconds: Duration
Возвращает Duration, равную этому числу микросекунд типа Int.
Примеры
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(15.microseconds) // 15us
// Large values can be accurately represented only with millisecond precision
println(9000000000000_775_807.microseconds) // 104166666d 16h 0m 0.775s
// Fractional part is rounded to the nearest integer nanosecond value
println(999.0004.microseconds) // 999us
println(999.0009.microseconds) // 999.001us
// Double.NaN.microseconds // will fail with IllegalArgumentException
//sampleEnd
}
val Long.microseconds: Duration
Возвращает Duration, равную этому числу микросекунд типа Long.
Примеры
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(15.microseconds) // 15us
// Large values can be accurately represented only with millisecond precision
println(9000000000000_775_807.microseconds) // 104166666d 16h 0m 0.775s
// Fractional part is rounded to the nearest integer nanosecond value
println(999.0004.microseconds) // 999us
println(999.0009.microseconds) // 999.001us
// Double.NaN.microseconds // will fail with IllegalArgumentException
//sampleEnd
}
val Double.microseconds: Duration
Возвращает Duration, равную этому числу микросекунд типа Double.
В зависимости от величины значение округляется до целого числа наносекунд или миллисекунд.
Вызывает исключение
если это значение типа Double равно NaN.
Примеры
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(15.microseconds) // 15us
// Large values can be accurately represented only with millisecond precision
println(9000000000000_775_807.microseconds) // 104166666d 16h 0m 0.775s
// Fractional part is rounded to the nearest integer nanosecond value
println(999.0004.microseconds) // 999us
println(999.0009.microseconds) // 999.001us
// Double.NaN.microseconds // will fail with IllegalArgumentException
//sampleEnd
}
© 2010–2026 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.time/-duration/-companion/microseconds.html