I’ve got an issue where I am writing a DataSet to XML that has a column of type DateTime and I want to control the output format.
DataSet data = LoadDataSet();
data.Tables[0].Rows[0]["MyDate"] = DateTime.Now;
data.WriteXml(myFile);
By default the format of the DateTime in the XML seems to be as follows:
2011-08-02T17:39:00-07:00
I’d like use a custom date format, or at the very least strip the timezone info.
Is there any way to control the format of the DateTime columns in my dataset XML?
My gut says no since I am assuming it is done this way to facilitate conversion of data across time zones but I’ve noticed that I can successfully read DataSet XML even if DateTime column tags omit the timezone data so I was hoping I can do something analogous when writing to XML.
There is one standard format for
DateTimein XML. That’s the format thatWriteXmlwill use. If you need a different format, then you need to not useDateTime. As others have said, useStringinstead.