Is there a standard way in .NET/C# to convert a datetime object to ISO 8601 format yyyy-mm-dd hh:mm:ss?
Or do I need to do some string manipulation to get the date string?
ParseExact(String, String, IFormatProvider) Converts the specified string representation of a date and time to its DateTime equivalent using the specified format and culture-specific format information. The format of the string representation must match the specified format exactly.
To use the strict ISO8601
, you can use the s
(Sortable) format string:
myDate.ToString("s"); // example 2009-06-15T13:45:30
It's a short-hand to this custom format string:
myDate.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss");
And of course, you can build your own custom format strings.
More info:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With