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.
ambuliAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

Dave BaldwinFixer 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.
Julian HansenCommented:
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)
}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.