Json Date Serialization Timezone

Posted on by
Json Date Serialization Timezone Rating: 7,3/10 1447votes

Hi, I've been experimenting with the DateTime deserialization and have some strange behaviour. Using this code: DataContractJsonSerializer dcjs = new DataContractJsonSerializer(typeof(DateTime)); DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0).ToUniversalTime(); dcjs.WriteObject(Response.OutputStream, dateTime); I would be expecting the response to be: /Date(0) / but am actually getting /Date(-39600000) / Am I missing something here? According to this article it's meant to be the ticks since 1/1/1970. Even the example given - 'A date and time in UTC like November 29, 1989, 4:55:30 AM would be written out as ' @1@.' , using this calculator does not work. Need For Speed Most Wanted 2012 Origin Keygen Download there. Thanks for your help in advance.

Ok, so that actually does make sense as i'm in a +11 hour offset from UTC. So i'll refrase the question to that of the original bug I had. Say for example that I change the date to 1/1/2000 DataContractJsonSerializer dcjs = new DataContractJsonSerializer(typeof(DateTime)); DateTime dateTime = new DateTime(2000, 1, 1); dcjs.WriteObject(Response.OutputStream, dateTime); The result I get is: ' /Date(00+1100) /' Placed into the calculator I provided above that ticks translates into GMT: Fri, 29 Dec 31967 16:00:00 GMT Your timezone: Saturday, 30 December 31967 3:00:00 AM Which is not 11 hours offset. If you remove the last 3 digits from the end then you get the correct ticks, and that appears to work in all cases, but the question is why? Cheers, AussieGuy.

Introduction Most of the time, data transfer during Ajax communication is facilitated using JSON format. While JSON format is text based, lightweight and simple it doesn't offer many data types. The data types supported in JSON include string, number, boolean, array, object and null. This support for limited data types poses some difficulties while dealing with dates.

Date uploadTime; //ellipsis Getter、Setter } This class is serialized to json, it was 8 hours (because in China, the time zone is GMT+8) with my local running environment. I wrote this before: @JsonFormat(pattern='yyyy-MM-dd HH:mm:ss',timezone = 'GMT+8') ,This is no problem. But now there is a project to.

Give More Feedback

Comments are closed.