Spec-Zone.ru › Kotlin 2

fromEpochMilliseconds

kotlin-stdlib/kotlin.time/Instant/Companion/fromEpochMilliseconds

Начиная с Kotlin: 2.3

fun fromEpochMilliseconds(epochMilliseconds: Long): Instant

Возвращает Instant, который находится на расстоянии epochMilliseconds миллисекунд от момента эпохи 1970-01-01T00:00:00Z.

Гарантируется, что любое значение epochMilliseconds можно представить в виде Instant.

Обратите внимание, что Instant также поддерживает наносекундную точность с помощью fromEpochSeconds.

См. также

Instant.toEpochMilliseconds

Примеры

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 
   // Creating an Instant representing the Unix epoch.
val instant1 = Instant.fromEpochMilliseconds(0)
// Creating an Instant from a specific number of milliseconds since the Unix epoch.
val instant2 = Instant.fromEpochMilliseconds(1_000_000_000_123)

// toEpochMilliseconds returns the exact millisecond value provided during construction.
println(instant1.toEpochMilliseconds()) // 0
println(instant2.toEpochMilliseconds()) // 1000000000123

// The string representation of the constructed instants.
println(instant1) // 1970-01-01T00:00:00Z
println(instant2) // 2001-09-09T01:46:40.123Z 
   //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/-instant/-companion/from-epoch-milliseconds.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API