0

I have a question about the difference between two datetime strings.

My dates looks like this:
a) 2018-02-06T18:17:16+0100
b) 2018-02-06T17:20:00+0100

I need to count the difference in seconds between the two.

My code looks like this:

var d1 = new Date("2018-02-06T18:17:16+0100");
var d2 = new Date("2018-02-06T17:20:00+0100");
console.log(this.diff_seconds(d2, d1));

 diff_seconds(dt2, dt1) {
    var diff = (dt2.getTime() - dt1.getTime());
    diff /= (60 * 60);
    return Math.abs(Math.round(diff));
  }

This code returns 954 seconds, but it's wrong value, the right value should be bigger.

CodeBoyCode
  • 2,227
  • 12
  • 29
Roman Šimr
  • 81
  • 1
  • 10

0 Answers0