Epoch & Unix Timestamp in Java

Get the current epoch timestamp

long epochSeconds = java.time.Instant.now().getEpochSecond();

Convert epoch to date

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

Convert date to epoch

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

Java notes

System.currentTimeMillis() returns milliseconds; Instant.getEpochSecond() returns seconds. Prefer java.time (Java 8+) over the legacy java.util.Date API.

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

Other languages

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