DISABLE ADBLOCK

ADBlock is blocking some content on the site

ADBlock errore

Would event.timeStamp and Date.getTime have the same reference?

StackOverflow https://stackoverflow.com/questions/18165298
 Checked

Question

Would event.timeStamp and Date.getTime() return same values if taken at the exact same time?

For instance, could I use getTime() in order to calculate how much time passed since an event occurred, or might it happen that the 2 use different epoch / references?

Solution

No, they're always on the same reference, that is UTC, which is the time zone of all date internal storages.

You can also use Date.now().

OTHER TIPS

It depends on the browser.

Using the following HTML document I got different results using different browsers:

<!DOCTYPE html>
<html>
<body>

<div id="foo">onclick delay:</div>
<button onclick='var n=document.getElementById("foo"); n.innerHTML="onclick delay: "+((new Date).getTime()-event.timeStamp)+"ms"'>Click</button>

</body>
</html>

The delay printed on screen is:

Firefox: large number

IE: -4ms .. 0ms

Chrome: 0ms .. 2ms

Opera: 0ms .. 2ms

=> You cannot really use it if your code should work in different browsers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow