Krunal Joshi
Krunal Joshi

Reputation: 55

I get two time in string format in angular 2 and I want to get difference between that two time in angular2

for the below code I got the error NaN:

      for (let item of this.list) {
                if (item.pin.length == 2) {
                    var inTime = item.pin[0].time;
                    var outTime = item.pin[1].time;
                    var timeDuration = outTime - inTime;
                }
            }

Upvotes: 0

Views: 37

Answers (1)

Lukas
Lukas

Reputation: 168

You could use the date object in javascript. Just convert both strings into the a date using something like this:

inTime = new Date(item.pin[0].time);
outTime = new Date(item.pin[1].time);
timeDuration = outTime - inTime;

In this case, the timeDuration will be in milliseconds.

Upvotes: 2

Related Questions