How do I calculate a duration time?

Ibonesh picture Ibonesh · Mar 19, 2013 · Viewed 60.1k times · Source

I am developing a web-based application to capture start time and end time from system date-time but my main problem is that I don't know how can I get the duration time, between start and end time for downtime.

 //Function to get current start time
  var startTime = setInterval(function () { start() }, 1000);

  function start() {
    var startDate = new Date();
    var timeStart = startDate.toLocaleTimeString();
  $("#setCount").html(timeStart);
 }

Answer

Sergio picture Sergio · Mar 19, 2013

Do you mean this:

var date1 = new Date();
var date2 = new Date();
var diff = date2 - date1; //milliseconds interval

upd

check JSFiddle