to Java Instant
Начиная с Kotlin: 2.3
fun Instant.toJavaInstant(): Instant
Преобразует это значение kotlin.time.Instant в значение java.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 Kotlin Instant.
val kotlinInstant = Instant.fromEpochMilliseconds(10)
// It can be converted to a corresponding Java Instant.
val javaInstant = kotlinInstant.toJavaInstant()
// The Java Instant will represent the same moment in time,
// and can be passed to APIs that expect a Java Instant.
println(javaInstant.toEpochMilli()) // 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-java-instant.html