
ISO 8601 is a general, international standard on how the complex representation of time stamps can be formulated in a general way - including the consideration of time formats, time zones and resolution.
Therefore, ISO 8601 is generally recommended for the exchange of time information, whether in databases, XML files or any other potential technology-neutral exchange format.
.NET does not have its own method for outputting ISO 8601, but it does have a standard-compliant option when formatting time objects: the o parameter.
To get a format like 2020-01-17T10:20:30.0000000Z you can this snippet:
1
2 DateTime dat = new DateTime(2020, 1, 17, 10, 20, 30, DateTimeKind.Utc);
3 Console.WriteLine("{0} ({1}) --> {0:o}", dat, dat.Kind);
My brain is unfortunately filled with a lot of nonsense, so that I keep forgetting that “o” is the appropriate format option. Therefore I wrote a little extension:
1 public static string ToISO8601(this DateTimeOffset dt)
2 {
3 return dt.ToString("o");
4 }
5 public static string ToISO8601(this DateTime dt)
6 {
7 return dt.ToString("o");
8 }
Finally you can just write
1Console.WriteLine(dt.ToISO8601);
Related articles

Mar 17, 2026 · 15 min read
GitHub Copilot - Custom Agents for Full-Stack Teams: A Practical Operating Model for .NET, React and Azure
GitHub Copilot custom agents allow teams to define specialized AI assistants, each with its own role, tool access and behavioral boundaries. …

Mar 10, 2026 · 15 min read
.NET NuGet Trusted Publishing with GitHub Actions
Publishing NuGet packages has traditionally required one uncomfortable compromise: a long-lived API key had to exist somewhere in the …

Mar 09, 2026 · 7 min read
C# 15 Unions: Unions are finally in .NET
After many years of workarounds, design discussions and library-level substitutes, unions are finally becoming a first-class part of C#. The …
Let's Work Together
Looking for an experienced Platform Architect or Engineer for your next project? Whether it's cloud migration, platform modernization or building new solutions from scratch - I'm here to help you succeed.

Comments