Unix Timestamp in Kotlin

Use `kotlinx-datetime` for multiplatform code, or `java.time` if you're JVM-only.

Common Operations

Get current Unix timestamp (kotlinx-datetime)

import kotlinx.datetime.Clock
val ts = Clock.System.now().epochSeconds
// 1706745600

Get current Unix timestamp (java.time)

import java.time.Instant
val ts = Instant.now().epochSecond
// 1706745600

Convert Unix timestamp to Instant

import kotlinx.datetime.Instant
val instant = Instant.fromEpochSeconds(1706745600)

Format as ISO 8601

Clock.System.now().toString()
// '2024-01-31T22:40:00Z'

Other Languages

Need the full converter? Open the Timestamp Converter →