Utf8jsonreader Datetimeoffset Parsing Rfc 3339 May 2026

If you need UTC normalization:

public static DateTimeOffset GetDateTimeOffsetRfc3339(ref this Utf8JsonReader reader) if (reader.TokenType != JsonTokenType.String) throw new JsonException($"Expected string, got reader.TokenType"); // Fast path: use built-in conversion if possible (avoids custom parse) if (reader.TryGetDateTimeOffset(out DateTimeOffset dto)) return dto; utf8jsonreader datetimeoffset parsing rfc 3339

✅ Works because the built-in DateTimeOffsetConverter handles RFC 3339. When reading token-by-token and encountering a JsonTokenType.String that contains an RFC 3339 date: If you need UTC normalization: public static DateTimeOffset

DateTimeOffset dto = reader.GetDateTimeOffsetRfc3339(); out DateTimeOffset result))

| Example | Meaning | |----------------------------------|-----------------------| | 2023-10-05T14:30:00Z | UTC | | 2023-10-05T14:30:00+02:00 | UTC+2 | | 2023-10-05T14:30:00.123-05:00 | UTC-5 with fraction |

throw new JsonException($"Invalid RFC 3339 DateTimeOffset format: dateString");

if (DateTimeOffset.TryParseExact(s, rfc3339Pattern, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out DateTimeOffset result))