When I serialize the current time as a DateTime using the DataContractJsonSerializer I get the following 1307654074638-0500.
I'd like to generate my own JSON that could be deserialized by the DataContractJsonSerializer, but I can't figure out how to generate a DateTime with the same format.
I believe it's using the number of milliseconds since the epoch as it's base, but I keep getting numbers that are off by around 6 hours. I believe this has something to do with the Timezone (I'm in Central Time) which would make sense.
var myDate = DateTime.Now; var epoch = new DateTime(1970, 01, 01, 01, 0, 0); var serializer = new DataContractJsonSerializer(typeof (DateTime)); var ms = new MemoryStream(); serializer.WriteObject(ms, myDate); Console.WriteLine(Encoding.UTF8.GetString(ms.ToArray())); Console.WriteLine((myDate.AddTicks(-epoch.Ticks)).Ticks / 10000); outputs
"\/Date(1307654587318-0500)\/" 1307632987318 or for easier comparison
1307654587318-0500 1307632987318