I have the following XSD definition:
public class Test
{
private System.DateTime time;
[System.Xml.Serialization.XmlElementAttribute(DataType = "time")]
public System.DateTime Time
{
get
{
return this.time;
}
set
{
this.time = value;
}
}
}
I now have the following code:
var p = new Test
{
Time = DateTime.UtcNow
};
var xml = ToXml(p);
Console.WriteLine(xml);
Console.ReadLine();
And the following to serialize the xml:
public static string ToXml(Test value)
{
var settings = new XmlWriterSettings();
settings.Encoding = new UnicodeEncoding(false, false);
settings.Indent = false;
settings.OmitXmlDeclaration = true;
using (var textWriter = new StringWriter())
{
using (XmlWriter xmlWriter = XmlWriter.Create(textWriter, settings))
new XmlSerializer(typeof(Test)).Serialize(xmlWriter, value);
return textWriter.ToString();
}
}
The above code outputs the time like this:
<Time>15:24:43.2588160+00:00</Time>
I would like this in UTC format. e.g.
<Time>15:24:43.00Z</Time>
How can I achieve this?
I have no control over the XSD but I can change the Serializer method if required.
Very similar to this question but I can't edit the XSD: