One of the features of the new Date Time API in Java 8 is supposed to be nanosecond precision. However when I print the current Date Time to the console like so
DateTimeFormatter formatter = DateTimeFormatter
.ofPattern("yyyy-MM-dd'T'HH:mm:ss,nnnnnnnnnZ");
System.out.println(OffsetDateTime.now().format(formatter));
I only see millisecond precision: 2015-11-02T12:33:26,746000000+0100
The operating system does seem to support nanosecond precision. When I print the current date time via the Terminal
date -Ins
I see 2015-11-02T12:33:26,746134417+0100
How do I get nanosecond precision in Java? I'm running Oracle Java 1.8.0_66 on Ubuntu 14.04 64-bit
Clock
captures the current moment in up to nanosecond resolution (depending on the capability of your host hardware clock). – Eastertide