I would like to be able to Serialize a DateTime with a specific Time Zone that is not the server, nor is it client time. Basically, any time zone. Is it possible to override
Don't serialize the DateTimeOffset
directly, but serialize a string instead:
// Don't serialize this one
[System.Xml.Serialization.XmlIgnore]
public System.DateTimeOffset metadataDateTime
{
get { ... }
set { ... }
}
// Serialize this one instead
[System.Xml.Serialization.XmlAttribute("metadataDateTime")]
public string metadataDateTimeXml
{
get { /* format metadataDateTime to custom format */ }
set { /* parse metadataDateTime from custom format */ }
}
This was discussed 2 days ago. Does this do it for you?
C# serializing Class to XML where one of class properties is DateTime. How to make this property in ISO format?
You may want to use DateTimeOffset instead of a pure DateTime object.