I\'m trying to cleanup a mix of various code around datetime management to only Java 8 java.time namespace. Right now I have a small issue with the default DateTimeFormatter for
OK, I looked at the the source code and it's pretty straightforward:
DateTimeFormatter formatter = new DateTimeFormatterBuilder().appendInstant(3).toFormatter();
I hope it works for all scenarios, and it can help someone else. Don't hesitate to add a better/cleaner answer.
Just to explain where it comes from, in the JDK's code,
ISO_INSTANT
is defined like this:
public static final DateTimeFormatter ISO_INSTANT;
static {
ISO_INSTANT = new DateTimeFormatterBuilder()
.parseCaseInsensitive()
.appendInstant()
.toFormatter(ResolverStyle.STRICT, null);
}
And DateTimeFormatterBuilder::appendInstant
is declared as:
public DateTimeFormatterBuilder appendInstant() {
appendInternal(new InstantPrinterParser(-2));
return this;
}
And the constructor InstantPrinterParser
signature is:
InstantPrinterParser(int fractionalDigits)