How to Quickly Convert a JavaScript Date Object Into a Timestamp

One of things we often have to do in JavaScript is compare dates to see how much time has passed. To this, you would usually do something like this:

var start,
    stop,
    elapsedMilliseconds;


    start = new Date();
    someProcess();
    stop = new Date();
    elapsedMilliseconds = stop.getTime() - start.getTime();
    document.write(elapsedMilliseconds + " Milliseconds have passed");

However, there’s a simpler way:

var start,
    stop;

    start = +new Date();
    someProcess();
    stop = +new Date();
    document.write(stop-start + " Milliseconds have passed");

When you add the plus-sign infront of the new operator, the date returned is automatically converted into a timestamp allowing you to quickly assess the amount of milliseconds that have passed.

What other time-saving shortcuts do you know about in JavaScript? Feel free to share them in the comments below.