GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing javaevolved.dev — Instant with nanosecond precision | java.evolved
Date/Time
Intermediate
Instant with nanosecond precisionGet timestamps with microsecond or nanosecond precision. Code Comparison
✕ 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.
Why the modern way wins
🎯
Higher precisionMicrosecond/nanosecond vs millisecond timestamps. 📐
Type-safeInstant carries its precision — no ambiguous longs. 🌐
UTC-basedInstant is always in UTC — no timezone confusion. Old Approach
Milliseconds
Modern Approach
Nanoseconds
Since JDK
9
Difficulty
Intermediate
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
Related patterns
Date/Time
Intermediate
HexFormatJava 8
// Pad to 2 digits, uppercase
String hex = String.format(
"%02X", byteValue);
// Parse hex string
int val = Integer.parseInt(
"FF", 16);
Java 17+
var hex = HexFormat.of()
.withUpperCase();
String s = hex.toHexDigits(
byteValue);
byte[] bytes =
hex.parseHex("48656C6C6F");
JDK 17+
→
Date/Time
Beginner
java.time API basicsPre-Java 8
// Mutable, confusing, zero-indexed months Calendar cal = Calendar.getInstance(); cal.set(2025, 0, 15); // January = 0! Date date = cal.getTime(); // not thread-safe Java 8+
LocalDate date = LocalDate.of(
2025, Month.JANUARY, 15);
LocalTime time = LocalTime.of(14, 30);
Instant now = Instant.now();
// immutable, thread-safe
JDK 8+
→
Date/Time
Beginner
Duration and PeriodPre-Java 8
// How many days between two dates?
long diff = date2.getTime()
- date1.getTime();
long days = diff
/ (1000 * 60 * 60 * 24);
// ignores DST, leap seconds
Java 8+
long days = ChronoUnit.DAYS
.between(date1, date2);
Period period = Period.between(
date1, date2);
Duration elapsed = Duration.between(
time1, time2);
JDK 8+
→
|
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |