Epoch & Unix Timestamp in Scala

Get the current epoch timestamp

val epochSeconds = java.time.Instant.now.getEpochSecond

Convert epoch to date

val instant = java.time.Instant.ofEpochSecond(1718200000L)
val utc = instant.atZone(java.time.ZoneOffset.UTC)

Convert date to epoch

val epoch = java.time.LocalDateTime.of(2026, 6, 12, 0, 0)
  .toEpochSecond(java.time.ZoneOffset.UTC)

Scala notes

Scala uses java.time on the JVM. System.currentTimeMillis() is the millisecond shortcut; Scala.js users should reach for scala-java-time.

Check any value live with the epoch converter, or read what Unix time actually counts.

Other languages

C · C# · C++ · Dart · Go · Java · JavaScript · Kotlin · MySQL · Perl · PHP · PostgreSQL · Python · R · Ruby · Rust · SQLite · Swift · TypeScript