【发布时间】:2012-09-28 00:50:09
【问题描述】:
我有一个由 Visual Studio 2008 中的 XSD 工具自动生成的类;这个类看起来像这样:
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://www.xxx.com")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://www.xxx.com", IsNullable = false)]
public partial class Invoice
{
private DateTime startDateField;
// Some other fields goes here.
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public System.DateTime startDate
{
get
{
return this. startDateField;
}
set
{
this. startDateField = value;
}
}
}
当我序列化一个 Invoice 实例时,我得到一个如下所示的 xml:
<?xml version="1.0" encoding="utf-8"?>
<Invoice xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.xxx.com http://www.xxx/cfdv22.xsd" startDate ="2012-09-27T16:41:36-07:00">
… some other elements goes here.
</Invoice>
如果你看到属性 startDate 的值包含在末尾的时区。
在实现过程中是否有任何方法可以将日期时间对象转换为其表示形式,例如 yyyy-MM-ddTHH:mm:ss?或者删除时区的东西?
提前致谢。
【问题讨论】:
-
为什么????至少制作看起来不像精确时间日期的样本比大约在当天发生的时间更有意义。用“AlarmClock.TimeToWakup”替换你的样本怎么样...
标签: c# visual-studio-2008 xml-serialization