-2

I have the following values as Json. 14:49:09 00:16:46 00:00:05

I want to iterate through them while summing them up to come up with the final time of:

15:06:00 in Javascript

Etch
  • 191
  • 3
  • 9

1 Answers1

2

At first, you need to loop the elements, then take those values from JSON and create Date objects, parse to milliseconds, add together and go back to Date.

var time_sum = 0;
for(var i = 0; i < json.length; i++) {
    var obj = new Date(json[i]);
    time_sum += obj.getTime();
}
var total_date = new Date(time_sum);
Community
  • 1
  • 1
Mike B
  • 2,756
  • 2
  • 16
  • 28