Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# DateTime - RFC 3339 format

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?

like image 665
cweston Avatar asked Feb 16 '11 14:02

cweston


People also ask

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

Why do we write C?

It was mainly developed as a system programming language to write an operating system. The main features of the C language include low-level memory access, a simple set of keywords, and a clean style, these features make C language suitable for system programmings like an operating system or compiler development.


1 Answers

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.

like image 146
CodesInChaos Avatar answered Sep 21 '22 10:09

CodesInChaos