fromEpochSeconds

actual fun fromEpochSeconds(epochSeconds: Long, nanosecondAdjustment: Long): Instant(source)
actual fun fromEpochSeconds(epochSeconds: Long, nanosecondAdjustment: Int): Instant(source)
expect fun fromEpochSeconds(epochSeconds: Long, nanosecondAdjustment: Long = 0): Instant(source)

Returns an Instant that is the epochSeconds number of seconds from the epoch instant 1970-01-01T00:00:00Z and the nanosecondAdjustment number of nanoseconds from the whole second.

The return value is clamped to the boundaries of Instant if the result exceeds them. In any case, it is guaranteed that instants between DISTANT_PAST and DISTANT_FUTURE can be represented.

fromEpochMilliseconds is a similar function for when input data only has millisecond precision.

See also

Samples

import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.random.*
import kotlin.test.*
import kotlin.time.Duration.Companion.hours

fun main() { 
   //sampleStart 
   // Constructing an Instant from the number of seconds and nanoseconds since the Unix epoch
check(Instant.fromEpochSeconds(epochSeconds = 0) == Instant.parse("1970-01-01T00:00:00Z"))
check(Instant.fromEpochSeconds(epochSeconds = 1_000_001_234, nanosecondAdjustment = -1_234_000_000_001)
    == Instant.parse("2001-09-09T01:46:39.999999999Z")) 
   //sampleEnd
}

expect fun fromEpochSeconds(epochSeconds: Long, nanosecondAdjustment: Int): Instant(source)

Returns an Instant that is the epochSeconds number of seconds from the epoch instant 1970-01-01T00:00:00Z and the nanosecondAdjustment number of nanoseconds from the whole second.

The return value is clamped to the boundaries of Instant if the result exceeds them. In any case, it is guaranteed that instants between DISTANT_PAST and DISTANT_FUTURE can be represented.

fromEpochMilliseconds is a similar function for when input data only has millisecond precision.

See also

Samples

import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.random.*
import kotlin.test.*
import kotlin.time.Duration.Companion.hours

fun main() { 
   //sampleStart 
   // Constructing an Instant from the number of seconds and nanoseconds since the Unix epoch
check(Instant.fromEpochSeconds(epochSeconds = 0) == Instant.parse("1970-01-01T00:00:00Z"))
check(Instant.fromEpochSeconds(epochSeconds = 1_000_000_000, nanosecondAdjustment = -1) == Instant.parse("2001-09-09T01:46:39.999999999Z")) 
   //sampleEnd
}
actual fun fromEpochSeconds(epochSeconds: Long, nanosecondAdjustment: Long): Instant(source)
actual fun fromEpochSeconds(epochSeconds: Long, nanosecondAdjustment: Int): Instant(source)