What is the difference between using new Date()
and new Date().getTime()
when subtracting two timestamps? (test script on jsFiddle)
Both of the following gives the same results:
var prev1 = new Date();
setTimeout(function() {
var curr1 = new Date();
var diff1 = curr1 - prev1;
}, 500);
var prev2 = new Date().getTime();
setTimeout(function() {
var curr2 = new Date().getTime();
var diff2 = curr2 - prev2;
}, 500);
Is there a reason I should prefer one over another?