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
java.time API in general does have nanosecond precision. For example:
DateTimeFormatter formatter = DateTimeFormatter .ofPattern("yyyy-MM-dd'T'HH:mm:ss,nnnnnnnnnZ"); OffsetDateTime odt = OffsetDateTime.of(2015, 11, 2, 12, 38, 0, 123456789, ZoneOffset.UTC); System.out.println(odt.format(formatter));
However, it's the clock value returned by
OffsetDateTime.now() which is returning a value which only has milliseconds.
Clock implementation in Java 8:
The clock implementation provided here is based on
System.currentTimeMillis(). That method provides little to no guarantee about the accuracy of the clock. Applications requiring a more accurate clock must implement this abstract class themselves using a different external clock, such as an NTP server.
So there's nothing inherently imprecise here - just the default implementation of
System.currentTimeMillis(). You could potentially create your own more precise subclass. However, you should note that adding more precision without adding more accuracy probably isn't terribly useful. (There are times when it might be, admittedly...)