//楼主,请不要走弯路 string xmlDateString = "2005-10-11T00:00:00.0000000+08:00"; DateTime yourDate = XmlConvert.ToDateTime(xmlDateString);完整例子, using System; using System.IO; using System.Xml;public class Sample { public static void Main() { XmlTextReader reader = new XmlTextReader("orderData.xml"); //Parse the file and pull out the order date and price. while (reader.Read()){ if (reader.NodeType==XmlNodeType.Element){ switch(reader.Name){ case "order": DateTime orderDate = XmlConvert.ToDateTime(reader.GetAttribute("date")); Console.WriteLine("order date: {0}", orderDate.ToString()); break; case "price": Double price = XmlConvert.ToDouble(reader.ReadInnerXml()); Console.WriteLine("price: {0}", price.ToString()); break; } } } //Close the reader. reader.Close(); } } 该示例使用文件 orderData.xml 作为输入。 <order date="2001-05-03"> <orderID>367A54</orderID> <custID>32632</custID> <price>19.95</price> </order> 当然也可以调用XmlConvert.ToDateTime()的重载方法.
date.ToString("yyyy-MM-dd HH:mm:ss");
date.ToString("yyyy-MM-dd");
string xmlDateString = "2005-10-11T00:00:00.0000000+08:00";
DateTime yourDate = XmlConvert.ToDateTime(xmlDateString);完整例子,
using System;
using System.IO;
using System.Xml;public class Sample
{ public static void Main()
{
XmlTextReader reader = new XmlTextReader("orderData.xml"); //Parse the file and pull out the order date and price.
while (reader.Read()){
if (reader.NodeType==XmlNodeType.Element){
switch(reader.Name){
case "order":
DateTime orderDate = XmlConvert.ToDateTime(reader.GetAttribute("date"));
Console.WriteLine("order date: {0}", orderDate.ToString());
break;
case "price":
Double price = XmlConvert.ToDouble(reader.ReadInnerXml());
Console.WriteLine("price: {0}", price.ToString());
break;
}
}
} //Close the reader.
reader.Close();
}
}
该示例使用文件 orderData.xml 作为输入。
<order date="2001-05-03">
<orderID>367A54</orderID>
<custID>32632</custID>
<price>19.95</price>
</order>
当然也可以调用XmlConvert.ToDateTime()的重载方法.