我有一个由 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?或者删除时区的东西?
提前致谢。