Chin Chin - 1 year ago 163
C# Question

Convert dateTime to ISO format yyyy-mm-dd hh:mm:ss in C#

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?

Answer Source

There is no standard format for the readable 8601 format. You can use a custom format:

theDate.ToString("yyyy-MM-dd HH':'mm':'ss")

(The standard format "s" will give you a "T" between the date and the time, not a space.)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download