Java Timestamp Converter

Current Unix Time
Advertisement

Java Timestamp Converter

Java has evolved significantly in its approach to time handling. The modern java.time API (introduced in Java 8) is far superior to the older java.util.Date and java.util.Calendar classes. For Unix timestamp handling in Java, the Instant class is the primary tool — it represents a specific moment on the timeline with nanosecond precision and has direct methods for converting to and from Unix timestamps.

If you're working with legacy code that uses java.util.Date, be aware that Date.getTime() returns milliseconds (not seconds), and the constructor also takes milliseconds. This means a seconds-precision Unix timestamp must be multiplied by 1000 before being passed to new Date(ts) — the same pattern as JavaScript.

Java timestamp code examples (modern java.time API)

Get current timestamp in seconds:
Instant.now().getEpochSecond() // long

Get current timestamp in milliseconds:
System.currentTimeMillis() // long, milliseconds
or: Instant.now().toEpochMilli()

Unix seconds to Instant:
Instant instant = Instant.ofEpochSecond(1700000000L);

Unix milliseconds to Instant:
Instant instant = Instant.ofEpochMilli(1700000000000L);

Instant to LocalDateTime (UTC):
LocalDateTime.ofInstant(instant, ZoneOffset.UTC)

LocalDateTime to Unix seconds:
LocalDateTime.of(2026, 4, 17, 10, 35, 0).toEpochSecond(ZoneOffset.UTC)

Format as ISO 8601:
DateTimeFormatter.ISO_INSTANT.format(instant) // "2023-11-14T22:13:20Z"

Advertisement
// Epoch → Human-readable date

Auto-detects seconds (10 digits), milliseconds (13), microseconds (16), nanoseconds (19)

Invalid timestamp. Please enter a numeric Unix timestamp.
// Date → Epoch timestamp
Please check the values — year (1970–9999), month (1–12), day (1–31), hour (0–23), min/sec (0–59).

Or paste a date string:

Could not parse that date string.
Advertisement

← Back to all tools

Copied!