Date/Time Średniozaawansowany

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();
Widzisz problem z tym kodem? Daj nam znać.
🎯

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.

Stare podejście
Milliseconds
Nowoczesne podejście
Nanoseconds
Od JDK
9
Poziom trudności
Średniozaawansowany
Instant with nanosecond precision
Dostępne

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.

Udostępnij 𝕏 🦋 in