Unix Timestamp in Java
Java has two main ways to get Unix timestamps: the legacy System.currentTimeMillis() (milliseconds) and the modern java.time.Instant API (Java 8+, recommended).
Code Examples
Current timestamp — milliseconds (classic)
long ms = System.currentTimeMillis();
Returns milliseconds since epoch. Available since Java 1.0. Widely used in legacy code and Android.
Current timestamp — seconds (classic)
long sec = System.currentTimeMillis() / 1000L;
Integer-divide by 1000 to get seconds. The L suffix ensures 64-bit arithmetic.
Instant API — seconds (Java 8+, recommended)
import java.time.Instant; long sec = Instant.now().getEpochSecond();
The modern java.time approach. Instant is immutable and timezone-safe. Prefer this over System.currentTimeMillis() in new code.
Instant API — milliseconds (Java 8+)
import java.time.Instant; long ms = Instant.now().toEpochMilli();
Millisecond precision with the modern Instant API.
Convert timestamp back to date
import java.time.*;
Instant instant = Instant.ofEpochSecond(timestamp);
ZonedDateTime zdt = instant.atZone(ZoneId.of("UTC"));Convert a Unix timestamp back to a ZonedDateTime for formatting and display.
Note
Java's System.currentTimeMillis() returns milliseconds, not seconds — the same as JavaScript's Date.now(). The java.time package (introduced in Java 8) is the preferred API for new code; avoid the legacy java.util.Date and Calendar classes.
Main Epoch Converter
Use the homepage when you need epoch to date, date to epoch, or a full epoch converter
This Java 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.