Date/Time Intermediate

Get timestamps with microsecond or nanosecond precision.

โœ• Java 8
// Millisecond precision only
long millis =
    System.currentTimeMillis();
// 1708012345678
โœ“ Java 9+
// Microsecond/nanosecond precision
Instant now = Instant.now();
// 2025-02-15T20:12:25.678901234Z
long nanos = now.getNano();
See a problem with this code? Let us know.
๐ŸŽฏ

Higher precision

Microsecond/nanosecond vs millisecond timestamps.

๐Ÿ“

Type-safe

Instant carries its precision โ€” no ambiguous longs.

๐ŸŒ

UTC-based

Instant is always in UTC โ€” no timezone confusion.

Old Approach
Milliseconds
Modern Approach
Nanoseconds
Since JDK
9
Difficulty
Intermediate
Instant with nanosecond precision
Available

Widely available since JDK 9 (Sept 2017)

Java 9 improved the clock resolution so Instant.now() captures microsecond precision on most platforms (nanosecond on some). The old currentTimeMillis() only gives milliseconds.

Share ๐• ๐Ÿฆ‹ in โฌก