I am facing a strange problem. At first, when i insert a record in XML containing a date property which is binded to a DatePicker in XAML. The Element is in this form 2011-01-22T00:00:00
Then there is a update page, which is filled with the values read from XML. I am reading date like this Date = DateTime.Parse(record.Element("Date").Value;
Now when i click update, and replace the date value like this record.Element("Date").Value = Date. The format Changes and Date element is like this 22-01-2开发者_如何学C011 00:00:00
I found the reason for this format Conversion. Actually at first i am directly inserting the date into xml like this doc.Element("root").Add(new XElement("Date", dt)))
but while updation, the date is first converted to string and then updated/added to XML.
Conclusion
- Direct Insertion of DateTime into XML has the SortableDateTimePattern (based on ISO 8601) using local time; with this format pattern, the formatting or parsing operation always uses the invariant culture
- While Insertion of DateTime.ToString() Converts the value of DateTime object to its equivalent string representation. (Overrides ValueType ..::.ToString ()()().)
Thank you all.
精彩评论