Given a DateTime object, how do I get an ISO 8601 date in string format?

后端 未结 18 2222
暖寄归人
暖寄归人 2020-11-22 02:15

Given:

DateTime.UtcNow

How do I get a string which represents the same value in an ISO 8601-compliant format?

Note that ISO 8601 de

18条回答
  •  礼貌的吻别
    2020-11-22 02:32

    The "s" standard format specifier represents a custom date and time format string that is defined by the DateTimeFormatInfo.SortableDateTimePattern property. The pattern reflects a defined standard (ISO 8601), and the property is read-only. Therefore, it is always the same, regardless of the culture used or the format provider supplied. The custom format string is "yyyy'-'MM'-'dd'T'HH':'mm':'ss".

    When this standard format specifier is used, the formatting or parsing operation always uses the invariant culture.

    – from MSDN

提交回复
热议问题