0

Let's say we have two variables containing time in seconds simply like this:

const start = 1.496;
const end = 3.186;

apparently the difference here is ( end - start ==> 1.690 )

I used this but it fails to calculate it correctly:

new Date(end) - new Date(start) ==> "0:00:02"

const start = 1.496;
const end = 3.186;
console.log(new Date(end) - new Date(start))

How can we properly get the diff between two times given in ss.[milisecond] format like above example ?

Sara Ree
  • 2,963
  • 9
  • 31
  • 1
    You should not use `new Date` here at all. You'll get the same result when doing simply `end - start`. Then format as you see fit, e.g. `diff.toPrecision(4)`. – Bergi May 15 '22 at 20:35

0 Answers0