Get the Date String in Milliseconds

This is a cross-browser way to get a UNIX date string using Javascript. returns the date in modern browsers, however older browsers do not recognize it.  So if(! is then create a function for the older browser to use. Otherwise the function isn't created.

if (! { // for compatibility with browsers that don't suppport = function now() { return new Date().getTime(); }

time =;



var timeStart -;
    // do some long calculations ...
var timeEnd =;
document.getElementById("runtime").innerHTML = (timeEnd - timeStart);

Produces the result: 

The element with id = "runtime" is assigned the value of the length of time the script ran.

Creates a numeric string such as 1521918603730