to Kotlin Instant
Требования к платформе и версии: JS (2.3)
fun Date.toKotlinInstant(): Instant
Преобразует JS Date в соответствующий Instant.
Требования к платформе и версии: JVM (2.3)
fun Instant.toKotlinInstant(): Instant
Преобразует это значение java.time.Instant в значение kotlin.time.Instant.
Примеры
import kotlin.test.*
import kotlin.time.*
import kotlin.time.Duration.Companion.hours
import kotlin.time.Duration.Companion.nanoseconds
import kotlin.time.Duration.Companion.seconds
fun main() {
//sampleStart
// Given a Java Instant.
val javaInstant = java.time.Instant.ofEpochMilli(10)
// It can be converted to a corresponding Kotlin Instant.
val kotlinInstant = javaInstant.toKotlinInstant()
// The Kotlin Instant will represent the same moment in time,
// and can be passed to APIs that expect a Kotlin Instant.
println(kotlinInstant.toEpochMilliseconds()) // 10
//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/to-kotlin-instant.html