I am getting datetime as inputs using multiple timepickers in AngularJS. I want to add all the time inputs(dynamic) to give me a total duration.
e.g: if i input
Date {Wed Feb 03 2016 02:07:44 GMT+0530 (India Standard Time)}
Date {Wed Feb 03 2016 05:09:05 GMT+0530 (India Standard Time)}
It should return
Date {Wed Feb 03 2016 07:16:49 GMT+0530 (India Standard Time)}
Here is my code: https://jsfiddle.net/nitishhardeniya/ytndyuck/
Using moment
var moment = require('moment');
var d1 = moment("Wed Feb 03 2016 02:07:44 GMT+0530", "ddd MMM DD YYYY HH:mm:ss Z");
var d2 = moment("Wed Feb 03 2016 05:09:05 GMT+0530", "ddd MMM DD YYYY HH:mm:ss Z");
var dur1 = moment.duration(d1.format("HH:mm:ss"));
var dur2 = moment.duration(d2.format("HH:mm:ss"));
var totalDur = dur1 + dur2;
var temp = d1.clone();
temp.startOf('day').add(totalDur);
console.log(temp.format()); // 2016-02-03T07:16:49+05:30
console.log(temp.format("ddd MMM DD YYYY HH:mm:ss Z")); // Wed Feb 03 2016 07:16:49 +05:30