No, this is not possible
On request: Yes, we know that there is no equivalent format pattern string of DateTimeFormatter.ISO_OFFSET_DATE_TIME
.
DateTimeFormatter.ISO_OFFSET_DATE_TIME
omits the seconds and/or nano of second if they are zero. If the nanos are non-zero “As many digits will be output as required.” There is no pattern letter or combination of pattern letters that will give you the same behaviour.
Deep inside DateTimeFormatter
, ISO_OFFSET_DATE_TIME
uses an ISO_LOCAL_TIME
, which in turn is defined in this way:
ISO_LOCAL_TIME = new DateTimeFormatterBuilder()
.appendValue(HOUR_OF_DAY, 2)
.appendLiteral(':')
.appendValue(MINUTE_OF_HOUR, 2)
.optionalStart()
.appendLiteral(':')
.appendValue(SECOND_OF_MINUTE, 2)
.optionalStart()
.appendFraction(NANO_OF_SECOND, 0, 9, true)
.toFormatter(ResolverStyle.STRICT, null);
Which is the way to obtain the dynamic behaviour: using a DateTimeFormatterBuilder
and its optionalStart
and appendFraction
methods.
As an aside, you don’t want to copy the behaviour of ISO_OFFSET_DATE_TIME
exactly. You will want to use the built-in formatter.
pattern = "uuuu-MM-dd'T'HH:mm:ss.SSSSSSSXXX"
, but that is fixed at 7 fractional seconds. You can't get dynamic number of fractional seconds with a pattern. – Curve-0500
vs-05:00
). – Curve