Returns the number of milliseconds from the epoch instant 1970-01-01T00:00:00Z.

Any fractional part of millisecond is rounded toward zero to the whole number of milliseconds.

If the result does not fit in Long, returns Long.MAX_VALUE for a positive result or Long.MIN_VALUE for a negative result.

See also


import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.random.*
import kotlin.test.*
import kotlin.time.Duration.Companion.hours
fun main() { 
   // Converting an Instant to the number of milliseconds since the Unix epoch
check(Instant.fromEpochMilliseconds(0).toEpochMilliseconds() == 0L)
check(Instant.fromEpochMilliseconds(1_000_000_000_123).toEpochMilliseconds() == 1_000_000_000_123L)
check(Instant.fromEpochSeconds(1_000_000_000, nanosecondAdjustment = 123_999_999)
    .toEpochMilliseconds() == 1_000_000_000_123L)