I serialized an object containing current date in DateTimeOffset data type using DataContractJsonSerializer. This is what I get as output:
<root type="object">
<blah type="object">
<DateTime>/Date(1315565372414)/</DateTime>
<OffsetMinutes type="number">300</OffsetMinutes>
</blah>
</root>
How do I make sense of this? How do I convert the number 1315565372414 back to a date?
My client is receiving this thing in python and would want to change it back to date.
I’m not sure if these are ticks or seconds since epoch but both of them yield incorrect result.
Following is my code in .net to convert it back but the results are absurd
Console.WriteLine(new DateTime(1970, 1, 1).AddTicks(1315565372414));
If I try AddSeconds; it throws value out of range exception.
Here is how I’m serializing the date:
[DataContract]
public class Test
{
[DataMember]
public DateTimeOffset blah { get; set; }
}
var serializer = new DataContractJsonSerializer(typeof(Test));
var writer = new StringWriter();
serializer.WriteObject(new XmlTextWriter(writer), new Test() { blah = DateTimeOffset.Now });
string output = writer.ToString();
Console.WriteLine(output);
It is number of miliseconds since epoch. To deserialize it we need to do following:
References: