Skip to content

Period.ToString Method

Definition

Namespace: Corvus.Text.Json
Assembly: Corvus.Text.Json.dll
Source: Period.cs

ToString()

Returns this string formatted according to the ISO8601 duration specification used by JSON schema.

public override string ToString()

Returns

string

A formatted representation of this period.

Remarks

The result is a valid RFC 3339 Appendix A duration (the grammar used by the JSON Schema duration format), and is produced by the same formatter used when writing a period to a JSON document, so it always round-trips back through TryParse. That grammar does not permit fractional seconds, so any sub-second component is rounded to the nearest whole second before formatting (rounding halves away from zero). Zero-valued units are omitted where the grammar allows, so for example a one-day, two-hour period is formatted as P1DT2H rather than P0Y0M1DT2H0M0S.

Applies To

Product Versions
.NET 9, 10
.NET Standard 2.0, 2.1

Collaborate with us on GitHub

The source for this content can be found on GitHub, where you can also create and review issues and pull requests.

Open an issue