On Sat, 9 Aug 2025 13:52:45 GMT, ExE Boss <d...@openjdk.org> wrote:

> How about using different patterns for parsing and printing instead?

In fact, the current `DateTimeFormatterBuilder.InstantPrinterParser` already 
use different behavior for formatting, i.e., only print time in "Z" (no offset).

The following change:

--- a/src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java
+++ b/src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java
@@ -3887,7 +3887,7 @@ public int parse(DateTimeParseContext context, 
CharSequence text, int position)
                     .appendValue(MINUTE_OF_HOUR, 2).appendLiteral(':')
                     .appendValue(SECOND_OF_MINUTE, 2)
                     .appendFraction(NANO_OF_SECOND, minDigits, maxDigits, true)
-                    .appendOffsetId()
+                    .appendOffset("+HH:mm:ss", "Z")
                     .toFormatter().toPrinterParser(false);
             DateTimeParseContext newContext = context.copy();
             int pos = parser.parse(newContext, text, position);

will parse hour-only offset for `Instant.parse()` but I am not sure we would go 
for this, as other `ISO` formatters all use "MM" for minutes. @jodastephen any 
suggestions?

-------------

PR Comment: https://git.openjdk.org/jdk/pull/26708#issuecomment-3175834055

Reply via email to