java.time API
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 Real-world use cases for Java
- Storing event timestamps as epoch seconds in a Postgres or DynamoDB table shared across services.
- Building an audit trail where each action is logged with Instant.now().getEpochSecond().
- Converting Kafka message timestamps (epoch milliseconds) into Instant objects for windowing logic.
| Unix timestamp (seconds) | ISO 8601 (UTC) |
|---|---|
| 0 | 1970-01-01T00:00:00.000Z |
| 946,684,800 | 2000-01-01T00:00:00.000Z |
| 1,754,136,000 | 2025-08-02T12:00:00.000Z |
| 2,147,483,647 | 2038-01-19T03:14:07.000Z |
| 2,524,608,000 | 2050-01-01T00:00:00.000Z |
These are the same fixed timestamps used in the Java examples above — every conversion returns one of these values.
Frequently asked questions
How do I get the current Unix timestamp in Java?
System.currentTimeMillis() returns epoch milliseconds; divide by 1000 for seconds. The modern java.time way is Instant.now().getEpochSecond() or Instant.now().toEpochMilli().
How do I convert an epoch timestamp to a date in Java?
Instant.ofEpochSecond(1754136000L) builds an Instant directly, and .toString() emits ISO 8601. Use ZonedDateTime.ofInstant(instant, zoneId) to render it in a specific IANA timezone.
What is the difference between java.util.Date and java.time.Instant?
java.util.Date is a legacy mutable object with millisecond precision. java.time.Instant is the modern immutable replacement with nanosecond precision and direct epoch helpers, and it is the recommended API for new code.
Epoch to human date in Java
Try it live — convert any timestamp in Java-friendly format.
Seconds or milliseconds — the unit is auto-detected. Example: 1735689600
UTC ISO 8601
–
Local — auto
–
RFC 2822 / GMT
–
Seconds value
–
Relative time
–
Other programming languages
Copy-paste epoch conversion snippets in your favorite stack
More timestamp guides
Example values used above: epoch seconds = 1,754,136,000 · ISO 8601 = 2025-08-02T12:00:00.000Z. Curious how the numbers work? See the Unix epoch time FAQ, or view the current epoch time in any timezone.