I am trying to generate RFC 3339 compliant date strings (ie. '2008-03-19T00:00:00.0000000-04:00') however I seem to be having an issue with the offset being invalid. I am using the following:
private string GetDate(DateTime DateTime)
{
DateTime UtcDateTime = TimeZoneInfo.ConvertTimeToUtc(DateTime);
return XmlConvert.ToString(UtcDateTime, XmlDateTimeSerializationMode.Utc);
}
but this returns me with a value such as "1977-02-03T05:00:00Z"
I have also attempted using a specific format such as
utcDateTime.ToString("yyyy-MM-dd'T'HH:mm:ss.fffK", DateTimeFormatInfo.InvariantInfo);
But with the same results.
See this existing reference: How do I parse and convert DateTime's to the RFC 3339 date-time format?
UtcDateTime
is UTC, then why do you expect a time-zone different from 0? – ExcursiveZ
. At least that's what I remember. Has been some time since I read that RFC. – Excursive