-1

I need to find the difference, in hours, between two values(t1 and t2) t1(Now) code:

<td><!--tc:minutes--></td>

t2(then) code:

<td><!--tc:time.cost--></td>

For example t1 is 1:11 (1 hours, 11 minutes) and t2 is 1:05 (1 hours, 5 minutes)

How can I get the remaining time? 0:06 (0 hours, 6 minutes)? I think I need JavaScript function like HoursBetween in Delphi..

1 Answers1

0

// using Date objects
var start = Date.now();

// the event to time goes here:
doSomethingForALongTime();
var end = Date.now();
var elapsed = end - start; // elapsed time in milliseconds
// using built-in methods
var start = new Date();

// the event to time goes here:
doSomethingForALongTime();
var end = new Date();
var elapsed = end.getTime() - start.getTime(); // elapsed time in milliseconds
// to test a function and get back its return
function printElapsedTime(fTest) {
  var nStartTime = Date.now(),
      vReturn = fTest(),
      nEndTime = Date.now();

  console.log('Elapsed time: ' + String(nEndTime - nStartTime) + ' milliseconds');
  return vReturn;
}

yourFunctionReturn = printElapsedTime(yourFunction);