C # DateTime - RFC 3339 format

I'm trying to create date strings that meet the requirements of RFC 3339 (for example, "2008-03-19T00: 00: 00.0000000-04: 00"), but I seem to have an offset problem that is not valid. I am using the following:

private string GetDate(DateTime DateTime) { DateTime UtcDateTime = TimeZoneInfo.ConvertTimeToUtc(DateTime); return XmlConvert.ToString(UtcDateTime, XmlDateTimeSerializationMode.Utc); } 

but it returns me with a value such as "1977-02-03T05: 00: 00Z"

I also tried using a specific format like

  utcDateTime.ToString("yyyy-MM-dd'T'HH:mm:ss.fffK", DateTimeFormatInfo.InvariantInfo); 

But with the same results.


See current link: How to parse and convert DateTime to RFC 3339 date and time format?

+4
source share
1 answer

You convert your data to UTC, so its time zone shifted to UTC is 0:00. The RFC defines a convenient notation for UTC dates, the suffix Z So for me it looks like a valid data string.

+7
source

Source: https://habr.com/ru/post/1340005/


All Articles