xxxxxxxxxx
The above answer is wrong, we should always subtract to the endTime the firstTime to know the difference:
let startTime = new Date();
// do something
let timeDiff = new Date() - startTime;
console.log(`Elapsed time: ${timeDiff} (ms)`);
console.log(`Elapsed time: ${Math.round(timeDiff / 1000)} (seconds)`);
}