Serializing DateTime to time without milliseconds and gmt

前端 未结 2 1504
清酒与你
清酒与你 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:11

    You could create a string property that does the translation to/from your timeField field and put the serialization attribute on that instead the the real DateTime property that the rest of the application uses.

    0 讨论(0)
  • 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); }
    }
    
    0 讨论(0)
提交回复
热议问题