jsmreese / moment-duration-format

Format function plugin for the Moment Duration object.
MIT License
967 stars 121 forks source link

Format 'd:HH:mm:ss' duration ,wrong output #128

Closed cfkxzsat closed 5 years ago

cfkxzsat commented 5 years ago

Here's my code.

moment.duration(os.uptime(),"second").format('d:HH:mm:ss',{
    forceLength: true
})
// expected: 0:03:15:00
// output:  03:15:00

Did I write wrong?

jsmreese commented 5 years ago

You want to set trim to false.

moment.duration(os.uptime(),"second").format('d:HH:mm:ss',{
    trim: false
})

In this context (not trimming), forceLength wouldn't do anything, so you don't need to set it.