We are moving to Java 17 (correto17) from Java 11 (correto11). As part of this, we also have to upgrade Ubuntu to standard:6.0
from standard:4.0
in AWS as mentioned here.
We are observing that in Java 11 and Java 17 Instant.now()
output is a bit different.
For example,
System.out.println("Instant: " + Instant.now());
is giving output like below
- Java 11 -
Instant: 2022-12-12T18:04:27.267229Z
- Java 17 -
Instant: 2022-12-12T18:04:27.267229114Z
Can someone let me know what is causing this? How can I make the behaviour same in both the cases?
Instant.now()
can now return a value which has a non-zero "submicrosecond" part. – RizasOpenJDK Runtime Environment Homebrew (build 17.0.5+0)
andopenjdk version "17.0.5" 2022-10-18
I am not observing this change. It is returning the value same as in Java 11. Not sure if it is something specific tocorreta17
. – ProteaseInstant.toString()
to find it. What is different in your two cases is the value you are printing. The former has zeroes in the last places, which is why they are not printed. – Spectrogramcorretojava17
there are no extra zeroes and this behaviour is not same across all flavors of OpenJDK 17. For example,OpenJDK Runtime Environment Homebrew (build 17.0.5+0)
andopenjdk version "17.0.5" 2022-10-18
is also having zeroes in the last place like the way it was in JDK 11. – Protease2022-12-13T15:13:13.100Z
, or2022-12-13T15:13:13.000000100Z
, which I didn’t readily see documented, but may also not be in direct conflict with the documentation, which just states of the fraction of second: As many digits will be output as required. Is this what you are seeing too? And what would your desired output be instead? – SpectrogramDateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH:mm:ss.SSSSSSX").withZone(ZoneOffset.UTC).format(Instant.now())
. – Spectrogram