0

I have a moment.Duration object which I need to convert to string format HH:mm:ss (without any timezone conversion). I know we can do like

foobar.hours + ":" + foobar.minutes + ":" + foobar.seconds

But honestly I was hoping to have a better solution that just string manipulations.

Nikhil Agrawal
  • 47,018
  • 22
  • 121
  • 208
  • Does this answer your question? [How do I use format() on a moment.js duration?](https://stackoverflow.com/questions/13262621/how-do-i-use-format-on-a-moment-js-duration) – rMonteiro Feb 18 '20 at 09:52

2 Answers2

0

moment().format('HH:mm:ss'); if u have already moment object use like this

object.format('HH:mm:ss');

Brijesh Lukhi
  • 15
  • 1
  • 1
  • 9
0
var now = moment()
var then = moment().subtract(3, 'hours').subtract(20, 'minutes')

const duration = now.subtract(then)

duration.format("HH:mm:ss")

>> 03:20:00
Nicolai Lissau
  • 7,298
  • 5
  • 43
  • 57