I serialized an object containing the current date in the 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 can I understand that? How do I convert the number 1315565372414 to a date? My client gets this thing in python and would like to change it for today. Iโm not sure if these are tics or seconds from the era, but both of them give the wrong result. Below is my code in .net to convert it, but the results are absurd
Console.WriteLine(new DateTime(1970, 1, 1).AddTicks(1315565372414));
If I try AddSeconds; it throws an exception out of range.
This is how I serialize 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);
source share