Serializing DateTime to time without milliseconds and gmt

前端 未结 2 1502
清酒与你
清酒与你 2020-12-03 17:36

I have created a C# class file by using a XSD-file as an input. One of my properties look like this:

 private System.DateTime timeField;

 [System.Xml.Serial         


        
2条回答
  •  有刺的猬
    2020-12-03 18:25

    Put [XmlIgnore] on the Time property.

    Then add a new property:

    [XmlElement(DataType="string",ElementName="Time")]
    public String TimeString
    {
        get { return this.timeField.ToString("yyyy-MM-dd"); }
        set { this.timeField = DateTime.ParseExact(value, "yyyy-MM-dd", CultureInfo.InvariantCulture); }
    }
    

提交回复
热议问题