Javascript setTimeout() track the elapsed time between events.

Description

Javascript setTimeout() track the elapsed time between events.

var firstDate = new Date(); 

setTimeout(function() { 
       doEvent(firstDate); // w  w  w  .  ja va2  s . co m
}, 25000); 

function doEvent() { 
       var secondDate = new Date(); 
       var diff = secondDate - firstDate; 
       console.log(diff); // approx. 25000 
} 



PreviousNext

Related