# Adding Time values together in Javascript

Hi there,
I have a list of time values in the format of HH:MM:SS.  Is there a way to add them together and display in same format.
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fixer of ProblemsCommented:
I've never been able to find one.  Date and Time functions don't seem to consider or work with elapsed time arithmetic.  The only way I can think of to do this is to convert the values into seconds, add them and then convert back to HH:MM:SS.
Commented:
Is this what you were looking for. Function takes an array of times in format 'HH:MM:SS'
Working sample here
``````function getTimeTotal(times)
{
var result = 0;
for(var i = 0; i < times.length;i++) {
if (times[i].trim() != '') {
var hms = times[i].match(/(\d+):(\d+):(\d+)/);
result += parseInt(hms[1]) * 3600 + parseInt(hms[2]) * 60 + parseInt(hms[3]);
}
}
var hours = parseInt(result/3600);
var h = result % 3600;
var minutes = parseInt(h/60);
var seconds = h % 60;
return ("00" + hours).slice(-2) + ':' + ("00" + minutes).slice(-2) + ":" + ("00" + seconds).slice(-2)
}
``````

Experts Exchange Solution brought to you by