EpochTools

Code snippets / Java

Java Unix timestamp converter

Java's legacy `System.currentTimeMillis()` returns milliseconds. The modern `java.time` package makes the rest trivial: `Instant` is the epoch-friendly representation.

`Instant.ofEpochSecond()` goes from seconds to an instant, and `getEpochSecond()` goes back. `Instant.toString()` emits ISO 8601 automatically.

Current Unix timestamp (seconds)

long now = System.currentTimeMillis() / 1000;
System.out.println(now); // 1,754,136,000

Convert epoch seconds → ISO 8601 (UTC)

import java.time.Instant;
Instant instant = Instant.ofEpochSecond(1754136000L);
System.out.println(instant); // 2025-08-02T12:00:00Z

Convert ISO 8601 → epoch seconds

import java.time.Instant;
long secs = Instant.parse("2025-08-02T12:00:00Z").getEpochSecond();
System.out.println(secs); // 1754136000

Example values used above: epoch seconds = 1,754,136,000 · ISO 8601 = 2025-08-02T12:00:00.000Z

Need more languages? Browse all the Unix timestamp code snippets. Curious how the numbers work? See the Unix epoch time FAQ, or view the current epoch time in any timezone.

Epoch → Human Date

Try it live — convert any timestamp in Java-friendly format.

Seconds or milliseconds — the unit is auto-detected. Example: 1735689600

Waiting for input…

UTC ISO 8601

Local — auto

RFC 2822 / GMT

Seconds value

Relative time