Instant with nanosecond precision
Code Comparison
// Millisecond precision only
long millis =
System.currentTimeMillis();
// 1708012345678
// Microsecond/nanosecond precision Instant now = Instant.now(); // 2025-02-15T20:12:25.678901234Z long nanos = now.getNano();
Why the modern way wins
๐ฏ
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
JDK Support
Instant with nanosecond precision
Available
Widely available since JDK 9 (Sept 2017)
How it works
Java 9 improved the clock resolution so Instant.now() captures microsecond precision on most platforms (nanosecond on some). The old currentTimeMillis() only gives milliseconds.
Related Documentation
Proof