Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java 11 Instant.now() gives microsecond precision but we need nanosecond

db019464-cd05-4426-b3ec-fe843a576450Sep 26 2018 — edited Sep 26 2018

As Java 11 is released, we got it and tried to print Instant.now(). Our requirement is to give the time string in nanosecond precision.

We are spiking on AWS with centos7, we verified that system clock has precision upto nanos by firing

$ date +"%s %9N"

1537941601 130559008

But while printing Instant.now() with following formatter

DateTimeFormatter.ISO_INSTANT.withZone(ZoneOffset.UTC).format(instant)

It gives

2018-09-26T05:57:18.390390Z

and with following formatter

DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss[.SSSSSSSSS]").withZone(ZoneOffset.UTC)

it gives

2018-09-26T06:07:38.296302000

So, is that fair to say that support for nano precision is not present in java 11?

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 24 2018
Added on Sep 26 2018
1 comment
12,398 views