在.NET中使用DataSet.WriteXml当自定义DateTime格式 [英] Custom DateTime formats when using DataSet.WriteXml in .NET

查看:489
本文介绍了在.NET中使用DataSet.WriteXml当自定义DateTime格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我正在写一个DataSet以XML具有DateTime类型的列一个问题,我想控制的输出格式。

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);

在默认情况下在XML中的DateTime的格式似乎是如下:

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.

有什么办法来控制日期时间列的格式在我的数据集XML?

Is there any way to control the format of the DateTime columns in my dataset XML?

我的直觉说,没有,因为我假设是做这样便于跨时区的数据转换,但我注意到,我可以成功读取数据集XML即使时间列标签省略时区的数据,所以我希望我写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.

推荐答案

有在XML的的DateTime 一个标准格式。就是这样中WriteXML 将使用的格式。如果你需要一个不同的格式,那么你需要不使用的DateTime 。正如其他人所说,使用字符串代替。

There is one standard format for DateTime in XML. That's the format that WriteXml will use. If you need a different format, then you need to not use DateTime. As others have said, use String instead.

这篇关于在.NET中使用DataSet.WriteXml当自定义DateTime格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆