Skip to content

Commit 11eea81

Browse files
authored
Add note about omitted fractional-second digits when formatting DT(Offset)s in System.Text.Json (#16863)
* Add note about ommited fractional seconds when formatting DT(Offset)s in System.Text.Json * Address review feedback
1 parent f0b6a2b commit 11eea81

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

docs/standard/datetime/system-text-json-support.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,20 @@ The following levels of granularity are defined for formatting:
222222

223223
Used to format a <xref:System.DateTime> or <xref:System.DateTimeOffset> with fractional seconds and with a local offset.
224224

225-
If present, a maximum of 7 fractional digits are written. This aligns with the <xref:System.DateTime> implementation, which is limited to this resolution.
225+
If the [round-trip format](../base-types/standard-date-and-time-format-strings.md#the-round-trip-o-o-format-specifier) representation of a
226+
<xref:System.DateTime> or <xref:System.DateTimeOffset> instance has trailing zeros in its fractional seconds, then <xref:System.Text.Json.JsonSerializer>
227+
and <xref:System.Text.Json.Utf8JsonWriter> will format a representation of the instance without trailing zeros.
228+
For example, a <xref:System.DateTime> instance whose [round-trip format](../base-types/standard-date-and-time-format-strings.md#the-round-trip-o-o-format-specifier)
229+
representation is `2019-04-24T14:50:17.1010000Z`, will be formatted as `2019-04-24T14:50:17.101Z` by <xref:System.Text.Json.JsonSerializer>
230+
and <xref:System.Text.Json.Utf8JsonWriter>.
231+
232+
If the [round-trip format](../base-types/standard-date-and-time-format-strings.md#the-round-trip-o-o-format-specifier) representation of a
233+
<xref:System.DateTime> or <xref:System.DateTimeOffset> instance has all zeros in its fractional seconds, then <xref:System.Text.Json.JsonSerializer>
234+
and <xref:System.Text.Json.Utf8JsonWriter> will format a representation of the instance without fractional seconds.
235+
For example, a <xref:System.DateTime> instance whose [round-trip format](../base-types/standard-date-and-time-format-strings.md#the-round-trip-o-o-format-specifier)
236+
representation is `2019-04-24T14:50:17.0000000+02:00`, will be formatted as `2019-04-24T14:50:17+02:00` by <xref:System.Text.Json.JsonSerializer>
237+
and <xref:System.Text.Json.Utf8JsonWriter>.
238+
239+
Truncating zeros in fractional-second digits allows the smallest output needed to preserve information on a round trip to be written.
240+
241+
A maximum of 7 fractional-second digits are written. This aligns with the <xref:System.DateTime> implementation, which is limited to this resolution.

0 commit comments

Comments
 (0)