Skip to content Skip to sidebar Skip to footer

C# Javascriptserializer And Datetime.minvalue Crossing Timezones

Given that I have a client and a server, and a class like this: Client side: (TimeZone: UTC -8) class Foo { public int a; public DateTime MyTime { get; set; } } va

Solution 1:

Just pass them around as strings instead of DateTimes. yyyy-MM-dd hh:mm:ssZ will make it culture-neutral and cast it to UTC, which will ignore all time zones. This is used in the C# DateTime as code u.

Solution 2:

Use DateTimeOffset instead of DateTime. It looks like the serializer serializes the struct as follows:

{"a":1,"MyTime":"\/Date(-62135596800000)\/"}

This means that this string can be deserialized by either a DateTime and DateTimeOffset field on the server side. It looks like both of those deserialize the above string to midnight, so I'm assuming that the deserializer interprets the number as a +00:00 offset as it comes off the wire.

Post a Comment for "C# Javascriptserializer And Datetime.minvalue Crossing Timezones"