C#Datetime - RFC 3339フォーマット
質問
RFC 3339準拠の日付文字列(すなわち、「2008-03-19t00:00:00.0000000-04:00」)を生成しようとしていますが、オフセットが無効であるという問題があるようです。私は以下を使っています:
private string GetDate(DateTime DateTime)
{
DateTime UtcDateTime = TimeZoneInfo.ConvertTimeToUtc(DateTime);
return XmlConvert.ToString(UtcDateTime, XmlDateTimeSerializationMode.Utc);
}
.
しかし、これは "1977-02-03t05:00:00:00z" などの値で返します。
私はのような特定の形式を使用して試みました
.
utcDateTime.ToString("yyyy-MM-dd'T'HH:mm:ss.fffK", DateTimeFormatInfo.InvariantInfo);
しかし同じ結果を持つ。
この既存の参考文献を参照してください:
解決
You are converting your data to UTC, so its timezone offset to UTC is 0:00. The RFC defines a convenient notation for UTC dates, the suffix Z
. So this looks like a valid data-string to me.
所属していません StackOverflow