For Developers

Unix Timestamp in Java

How to get the current timestamp, convert it to a date, and convert a date back to a timestamp in Java — plus the specific mistake that trips up Java code more than any other.

Instant.now().getEpochSecond() // java.time, seconds
System.currentTimeMillis() // legacy, milliseconds
Instant.ofEpochSecond(1750000000)
LocalDateTime.parse("2025-06-15T12:00:00").toEpochSecond(ZoneOffset.UTC)

The Java-specific pitfall

Java genuinely has two conventions living side by side: the legacy Date/Calendar classes and System.currentTimeMillis() work in milliseconds, while the modern java.time package (Instant, LocalDateTime) defaults to seconds with nanosecond precision available separately. Mixing an old-API millisecond value into a new-API seconds-expecting method is a real, common bug in codebases mid-migration between the two.

Have a timestamp right now?

Paste it into the Timestamp ⇄ Date Converter to check it instantly, in any timezone, without writing any code. Working across several languages on the same project? The full Epoch Time in Programming Languages guide has all of them side by side for quick comparison.

Related

Related tools & reading