0

I have two date objects Date in the form of

let t1 = 2015-03-26T09:43:39.504
let t2 = 2015-03-26T10:43:39.504 

(These two times are retrieved by calling an API REST call).

How would I get the difference in time between the two (in the form of seconds)?

I've tried doing t1-t2 but the result is always 0.

Roka545
  • 3,404
  • 20
  • 62
  • 106

1 Answers1

1

Use getTime which returns the number of milliseconds since 1 January 1970 00:00:00.

let t1 = new Date('2015-03-26T09:43:39.504')
let t2 = new Date('2015-03-26T10:43:39.504')
const diff = (t2.getTime() - t1.getTime()) / 1000
Christian
  • 7,433
  • 4
  • 36
  • 61