Skip to content

Commit abd4401

Browse files
committed
Add note about ommited fractional seconds when formatting DT(Offset)s in System.Text.Json
1 parent 9d85dd9 commit abd4401

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,18 @@ 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 represenation 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 represenation 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+
If present, 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)