JavaScript Date() issue since Chrome 67

The issue

DateTime dateTime = (DateTime)new SqlDateTime();
dateTime = dateTime.AddMinutes(10);
JavaScriptSerializer js = new JavaScriptSerializer();
string jsonOutput = js.Serialize(dateTime);

Wow that’s a nice number, what the heck does it mean?

new Date(-2208991800000);
Sun Dec 31 1899 23:29:32 GMT+0019 (Midden-Europese standaardtijd)

The fix

var unixTime = new Date(0);
var jsonTime = new Date(-2208991800000);
var correction = (jsonTime.getTimezoneOffset() — unixTime.getTimezoneOffset()) * 60000;
new Date(jsonTime.getTime() + correction);
Mon Jan 01 1900 00:10:32 GMT+0019 (Midden-Europese standaardtijd)
var jsonTime = new Date(-2208991800000);
var correctedJsonTime = new Date(jsonTime.getTime() — (-1 * 60 * 60 * 1000));
correctedJsonTime.toUTCString();
“Mon, 01 Jan 1900 00:10:00 GMT”
new Date(“Mon, 01 Jan 1900 00:10:00 GMT”);
Mon Jan 01 1900 00:29:32 GMT+0019 (Midden-Europese standaardtijd)
new Date(“1900–01–01T00:10:00”);Mon Jan 01 1900 00:10:00 GMT+0019 (Midden-Europese standaardtijd)

The smallest unit of time is the tick, which is equal to 100 nanoseconds or one ten-millionth of a second. There are 10,000 ticks in a millisecond. The value of the Ticks property can be negative or positive to represent a negative or positive time interval.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store