Instant and Timestamps

Basic Java
≈ 2 min read

Instant is a specific point on the timeline

When it matters to record not “the local time on a clock,” but the moment when an event actually happened, you need Instant. It does not store a city name and does not show a familiar local date by itself. Its job is to represent a point on the timeline unambiguously relative to UTC.

Instant createdAt = Instant.now();
System.out.println(createdAt);

The string representation usually looks roughly like 2026-09-18T09:30:00Z. The Z means a zero offset from UTC. Such a value is convenient for storing the creation time of a record, the sending time of an event, the start of a request, or any other fact that must mean the same instant to every system.

Epoch time

Many protocols and data stores transfer an instant as a number relative to the epoch 1970-01-01T00:00:00Z. Instant can be converted to seconds or milliseconds from that point.

Instant instant = Instant.parse("2026-09-18T09:30:00Z");

long seconds = instant.getEpochSecond();
long millis = instant.toEpochMilli();

The reverse conversion is done with factory methods:

Instant fromMillis = Instant.ofEpochMilli(millis);
Do not mix up seconds and milliseconds. Both values are often called a “timestamp,” but a millisecond value is roughly a thousand times larger than a second value. When exchanging data, always check the unit defined by the contract.

Instant and local time

One Instant can be displayed differently in different time zones. To get a human-readable date and time, the rules of a zone must be applied to the instant.

Instant instant = Instant.parse("2026-09-18T09:30:00Z");

ZonedDateTime berlin = instant.atZone(ZoneId.of("Europe/Berlin"));
ZonedDateTime tokyo = instant.atZone(ZoneId.of("Asia/Tokyo"));

berlin and tokyo show different clock values, but they point to the same instant.

When to choose Instant

If a value answers the question “when exactly did this happen?”, Instant is usually a good base model. If the meaning is “every day at 09:00” or “a birthday on May 12,” an absolute instant appears only after additional context is added, and another type expresses the task more accurately.