2

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);

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

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
Yusuf
  • 51
  • 8
  • possible duplicate of [What's wrong with Java Date & Time API?](http://stackoverflow.com/questions/1969442/whats-wrong-with-java-date-time-api) – Paul Sweatte Feb 03 '14 at 23:04

2 Answers2

0

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;
tone
  • 1,374
  • 20
  • 47
0

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

awm
  • 6,526
  • 25
  • 24