0

I have to sum some hours and show total above 24hours.

example:

const result = moment('00:00:00', 'HH:mm:ss');

result.add(moment.duration('10:00:00'))
result.add(moment.duration('10:00:00'))
result.add(moment.duration('06:00:00'))

console.log(result.format('HH:mm:ss'));

the output is 02:00:00 and i want it to be 26:00:00.

L.Text
  • 19
  • 6
  • I suggest you to migrate from `momentjs`, [here](https://momentjs.com/docs/#/-project-status/) why – Raz Luvaton Sep 21 '21 at 17:00
  • Then why not just sum up the time by separating it into hours, minutes and seconds? – tomerpacific Sep 21 '21 at 17:01
  • Does this answer your question? [Get hours difference between two dates in Moment Js](https://stackoverflow.com/questions/25150570/get-hours-difference-between-two-dates-in-moment-js) – Raz Luvaton Sep 21 '21 at 17:03

1 Answers1

2

Sounds like you want a duration as a result, not a date. So use a duration instead:

const result = moment.duration();

result.add(moment.duration('10:00:00'))
result.add(moment.duration('10:00:00'))
result.add(moment.duration('06:00:00'))

console.log(result.asHours());
// print 26

console.log(`${result.asHours()}:${result.minutes}:${result.seconds}`);
// print 26:00:00
Christian Fritz
  • 20,641
  • 3
  • 42
  • 71