Convert DateTime to ISO 8601 String in C#
To convert DateTime to ISO 8601 we can usetoString()
method and pass "o" as parameter.Example
using System;
public class Example
{
public static void Main()
{
var newTime = DateTime.UtcNow.ToString("o");
Console.WriteLine(newTime);
}
}
Output
2022-02-06T04:10:15.7227016Z