开发者

JavaScriptDateTimeConverter gives different result on server

The code below works fine on local machine. On the other side, on server, it shifts date 1 day left.

JsonSerializer serializer = new JsonSerializer();
serializer.Converters.Add(new JavaScriptDateTimeConverter());

The value returning from database is: 2010-09-16 00:00:00.000

JsonSerializer gives 2010-09-16 on local and gives 2010-09-15 on server..

any ideas?


To clarify the problem i made a simple test;

string str = JsonConvert.SerializeObject(Convert.ToDateTime("2010-09-16 00:00:00.000"), new JavaScriptDateTimeConverter());
Response.Write(str);
开发者_Go百科

this code produce different results on different machines.. Why?

new Date(1284584400000) and new Date(1284588000000) or

Wed Sep 15 2010 23:00:00 and Thu Sep 16 2010 00:00:00


This could be a timezone issue. Is your server in a different time zone? Is it timezone-adjusting the dates and times?


It's a timezone issue. By default JavaScriptDateTimeConverter uses UTC dates. You need to create a SerializerSettings object, and set

settings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Local;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜