日期:2014-05-20  浏览次数:20796 次

很郁闷 帮我看看这段代码
DataSet   ds   =new   DataSet   ();
DataTable   dt   =new   DataTable   ();
DataColumn   time   =new   DataColumn   ( "Time ",System.Type.GetType( "System.DateTime "));
dt.Columns   .Add   (time);

ds.Tables   .Add   (dt);

DataRow   dr=dt.NewRow   ();


dr[ "Time "]=DateTime.Now;
dt.Rows   .Add   (dr);
dt.AcceptChanges   ();
ds.AcceptChanges   ();

ds.WriteXml   ( "Test.xml ");

////////////////////////////////////////
为什么我写进去的时间的格式是这样的:2007-01-31T15:07:24.5312500+08:00
而不时这样啊:2007-01-31   15:07:   24

------解决方案--------------------
DataSet ds = new DataSet();
DataTable dt = new DataTable();
DataColumn time = new DataColumn( "Time ", typeof(string));
dt.Columns.Add(time);

ds.Tables.Add(dt);

DataRow dr = dt.NewRow();


dr[ "Time "] = DateTime.Now.ToString();
dt.Rows.Add(dr);
dt.AcceptChanges();
ds.AcceptChanges();

ds.WriteXml( "Test.xml ");
------解决方案--------------------
把dr[ "Time "]=DateTime.Now;改成dr[ "Time "]=DateTime.Now.ToString( "yyyy-MM-dd HH:mm:ss ");