Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the correct format to use for Date/Time in an XML file

Tags:

.net

datetime

xml

What format do I use for Date/Time when writing to an XML file using .NET? Do I simply use DateTime.ToString(), or do I have to use a specific format?

like image 899
Jon B Avatar asked Oct 31 '08 19:10

Jon B


People also ask

How do I change the date format in XML?

Can use the following conversion code to convert UTC format string to any other DateTime format. string result = Convert. ToDateTime("2011-02-04T00:00:00+05:30"). ToString("MM/dd/yyyy h:mm:ss tt");

What date format should be used?

The international standard recommends writing the date as year, then month, then the day: YYYY-MM-DD. So if both Australians and Americans used this, they would both write the date as 2019-02-03. Writing the date this way avoids confusion by placing the year first.

What is XS dateTime?

Lexical form The lexical form of xs:dateTime is a finite-length sequence of characters of the following form: yyyy - mm - dd T hh : mm : ss . ssssssssssss zzzzzz . The following abbreviations describe this form: yyyy. A four-digit numeral that represents the year.


1 Answers

I always use the ISO 8601 format (e.g. 2008-10-31T15:07:38.6875000-05:00) -- date.ToString("o"). It is the XSD date format as well. That is the preferred format and a Standard Date and Time Format string, although you can use a manual format string if necessary if you don't want the 'T' between the date and time: date.ToString("yyyy-MM-dd HH:mm:ss");

EDIT: If you are using a generated class from an XSD or Web Service, you can just assign the DateTime instance directly to the class property. If you are writing XML text, then use the above.

like image 184
Ryan Avatar answered Sep 28 '22 20:09

Ryan