event.timeStamp

The difference in milliseconds between the time the browser created the event and January 1, 1970.

.event.timeStamp()🡢 Number

This property can be useful for profiling event performance by getting the event.timeStamp value at two points in the code and noting the difference. To simply determine the current time inside an event handler, use (new Date).getTime() instead.

Note: Due to a bug open since 2004, this value is not populated correctly in Firefox and it is not possible to know the time the event was created in that browser.

Display the time since the click handler last executed.

JS
<div>Click.</div>
CSS
div {
  height: 100px;
  width: 300px;
  margin: 10px;
  background-color: #ffd;
  overflow: auto;
}
HTML
var last, diff;
$("div").click(function (event) {
  if (last) {
    diff = event.timeStamp - last;
    $("div").append("time since last event: " + diff + "<br>");
  } else {
    $("div").append("Click again.<br>");
  }
  last = event.timeStamp;
});
DEMO

Looking for a Web Developer?

👋

Hi! I'm Basti, author of this site. If you are looking for a web developer with 15+ years of experience, holla at me!

Be it the good 'ol jQuery, vanilla JS or modern frameworks like Vue and Svelte, front- or backend, I can help you.

Just write me at jobs@jqapi.com :)