Unix Timestamp in Kotlin
Kotlin on the JVM uses java.time.Instant (recommended, Java 8+) or System.currentTimeMillis(). In Kotlin Multiplatform, kotlinx-datetime provides a cross-platform API.
Code Examples
Current timestamp (seconds) — Instant API
import java.time.Instant val seconds = Instant.now().epochSecond
The modern JVM approach. Instant is immutable and timezone-safe. Prefer this over System.currentTimeMillis() in new Kotlin code.
Current timestamp (milliseconds)
import java.time.Instant val ms = Instant.now().toEpochMilli()
Returns milliseconds since epoch as Long. Equivalent to System.currentTimeMillis() but via the modern java.time API.
Classic — System.currentTimeMillis()
val ms = System.currentTimeMillis() val seconds = ms / 1000L
Works on all JVM targets including older Android versions. Returns milliseconds — divide by 1000 for seconds.
Kotlin Multiplatform — kotlinx-datetime
// build.gradle.kts: implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.6.1")
import kotlinx.datetime.Clock
val seconds = Clock.System.now().epochSecondskotlinx-datetime works on JVM, Android, iOS (via Kotlin/Native), and JS. epochSeconds returns Long.
Convert timestamp to Instant and format
import java.time.*
val instant = Instant.ofEpochSecond(timestamp)
val zdt = instant.atZone(ZoneId.of("UTC"))
val formatted = zdt.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME)Reconstruct an Instant from a Unix timestamp, attach a timezone, and format as ISO 8601.
Note
Kotlin on Android historically used System.currentTimeMillis() (milliseconds). The java.time package requires API 26+ on Android, or use desugaring (coreLibraryDesugaring). For Kotlin Multiplatform targeting iOS, kotlinx-datetime is the only cross-platform option.
Main Epoch Converter
Use the homepage when you need epoch to date, date to epoch, or a full epoch converter
This Kotlin guide shows how to create and parse Unix timestamps in code. If your next step is broader search intent like epoch converter, epoch to date, epoch time to date, or unix epoch converter, jump back to the live homepage tools to paste a raw Unix value, auto-detect seconds versus milliseconds, and copy the readable answer instantly.