Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is what I found in my testing MVC3 (not really an answer). If the DateTime to be serialized is pre 2007 when the DST was changed in the US, any date serialization that is occuring on the server will be 1 hour off when dealing with DateTimes that falls in the hole where DST was changed. (http://en.wikipedia.org/wiki/DST_in_the_US). Basically it appears to be using the most recent DST rules for all dates. </p> <p>Example. </p> <pre><code>Server Time: Friday, March 12, 2004 10:15:00 AM JSON Serialization: /Date(1079115300000)/ JS Time Formated: 10:15 Saturday, March 13, 2004 10:15:00 AM JSON Serialization: /Date(1079201700000)/ JS Time Formated: 10:15 Sunday, March 14, 2004 10:15:00 AM JSON Serialization: /Date(1079288100000)/ JS Time Formated: 11:15 (failed used the post 2007 DST rules) Server Time: Monday, March 15, 2004 10:15:00 AM JSON Serialization: /Date(1079374500000)/ JS Time Formated: 11:15 (failed used the post 2007 DST rules) </code></pre> <p>The last two items have failed to serialize the data correctly. </p> <p>In this test case the server and the client are hosted on the same machine, and all patches have been applied. </p> <p>Code fragment from the server</p> <pre><code> public ActionResult GetDates() { return Json( GetTimeList(), "text/x-json", System.Text.Encoding.UTF8, JsonRequestBehavior.AllowGet); } private List&lt;TestModel&gt; GetTimeList() { List&lt;TestModel&gt; model = new List&lt;TestModel&gt;(); DateTime temp = new DateTime(2003, 1, 1, 10, 15, 0); int HourInc = 24; for (int i = 0; i &lt; 2200; i ++) { model.Add(new TestModel { ServerDate = temp.ToLongDateString() + " " + temp.ToLongTimeString(), ServerTime = temp, ServerTimeString = temp.ToString("HH:mm") }); temp = temp.AddHours(HourInc); } return model; } </code></pre> <p>Code from Client</p> <pre><code>&lt;script type="text/javascript"&gt; $(function () { $.getJSON('/test/GetDates', function (data) { var newhtml = ''; var s = '&lt;td&gt;'; var e = '&lt;/td&gt;'; newhtml = "&lt;tr&gt;&lt;th&gt;ServerDate&lt;/th&gt;&lt;th&gt;ServerTime&lt;/th&gt;&lt;th&gt;JsonDate&lt;/th&gt;&lt;th&gt;JsaonFormatedTime&lt;/th&gt;&lt;/tr&gt;"; $.each(data, function () { var formatedTime = formatDateTime(parseJSON(this.ServerTime)) var st = formatedTime == this.ServerTimeString ? "pass" : "fail"; newhtml += '&lt;tr class="' + st + '"&gt;'; newhtml += s + this.ServerDate + e; newhtml += s + this.ServerTimeString + e; newhtml += s + this.ServerTime + e; newhtml += s + formatedTime + e; newhtml + '&lt;/tr&gt;'; }) $('#test').html(newhtml) }); }); var reDateNet = /\/Date\((\-?\d+)\)\//i; function parseJSON (value) { if (value == '/Date(-62135568000000)/') return null; // .net min date else if (reDateNet.test(value)) { return new Date(parseInt(reDateNet.exec(value)[1], 10)); } return value; } function formatDateTime(dt) { var s = '', d = dt.getHours(); s += (d &lt; 10 ? '0' + d : d) + ':'; d = dt.getMinutes(); s += (d &lt; 10 ? '0' + d : d); return s; } &lt;/script&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload