EDIT: This is bad advice. Use "o", as above. "s" does the wrong thing.
I always use this:
dateTime.ToUniversalTime().ToString("s");
This is correct if your schema looks like this:
<xs:element name="startdate" type="xs:dateTime"/>
Which would result in:
<startdate>2002-05-30T09:00:00</startdate>
You can get more information here: http://www.w3schools.com/xml/schema_dtypes_date.asp
If you are manually assembling the XML string use var.ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss.fffffffZ"));
That will output the official XML Date Time format. But you don't have to worry about format if you use the built-in serialization methods.
The XmlConvert
class provides these kinds of facilities.
About DateTimes, in particular, be careful about obsolete methods.
See also: https://stackoverflow.com/a/7457718/1288109
What does the DTD have to say?
If the XML file is for communicating with other existing software (e.g., SOAP), then check that software for what it expects.
If the XML file is for serialisation or communication with non-existing software (e.g., the one you're writing), you can define it. In which case, I'd suggest something that is both easy to parse in your language(s) of choice, and easy to read for humans. e.g., if your language (whether VB.NET or C#.NET or whatever) allows you to parse ISO dates (YYYY-MM-DD) easily, that's the one I'd suggest.
If you are manually assembling the XML string use var.ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss.fffffffZ"));
That will output the official XML Date Time format. But you don't have to worry about format if you use the built-in serialization methods.
What does the DTD have to say?
If the XML file is for communicating with other existing software (e.g., SOAP), then check that software for what it expects.
If the XML file is for serialisation or communication with non-existing software (e.g., the one you're writing), you can define it. In which case, I'd suggest something that is both easy to parse in your language(s) of choice, and easy to read for humans. e.g., if your language (whether VB.NET or C#.NET or whatever) allows you to parse ISO dates (YYYY-MM-DD) easily, that's the one I'd suggest.
EDIT: This is bad advice. Use "o", as above. "s" does the wrong thing.
I always use this:
dateTime.ToUniversalTime().ToString("s");
This is correct if your schema looks like this:
<xs:element name="startdate" type="xs:dateTime"/>
Which would result in:
<startdate>2002-05-30T09:00:00</startdate>
You can get more information here: http://www.w3schools.com/xml/schema_dtypes_date.asp
The XmlConvert
class provides these kinds of facilities.
About DateTimes, in particular, be careful about obsolete methods.
See also: https://stackoverflow.com/a/7457718/1288109
EDIT: This is bad advice. Use "o", as above. "s" does the wrong thing.
I always use this:
dateTime.ToUniversalTime().ToString("s");
This is correct if your schema looks like this:
<xs:element name="startdate" type="xs:dateTime"/>
Which would result in:
<startdate>2002-05-30T09:00:00</startdate>
You can get more information here: http://www.w3schools.com/xml/schema_dtypes_date.asp
What does the DTD have to say?
If the XML file is for communicating with other existing software (e.g., SOAP), then check that software for what it expects.
If the XML file is for serialisation or communication with non-existing software (e.g., the one you're writing), you can define it. In which case, I'd suggest something that is both easy to parse in your language(s) of choice, and easy to read for humans. e.g., if your language (whether VB.NET or C#.NET or whatever) allows you to parse ISO dates (YYYY-MM-DD) easily, that's the one I'd suggest.
EDIT: This is bad advice. Use "o", as above. "s" does the wrong thing.
I always use this:
dateTime.ToUniversalTime().ToString("s");
This is correct if your schema looks like this:
<xs:element name="startdate" type="xs:dateTime"/>
Which would result in:
<startdate>2002-05-30T09:00:00</startdate>
You can get more information here: http://www.w3schools.com/xml/schema_dtypes_date.asp
If you are manually assembling the XML string use var.ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss.fffffffZ"));
That will output the official XML Date Time format. But you don't have to worry about format if you use the built-in serialization methods.
What does the DTD have to say?
If the XML file is for communicating with other existing software (e.g., SOAP), then check that software for what it expects.
If the XML file is for serialisation or communication with non-existing software (e.g., the one you're writing), you can define it. In which case, I'd suggest something that is both easy to parse in your language(s) of choice, and easy to read for humans. e.g., if your language (whether VB.NET or C#.NET or whatever) allows you to parse ISO dates (YYYY-MM-DD) easily, that's the one I'd suggest.
Source: Stackoverflow.com