Question: Is there any way I can use the [moment.js](http://momentjs.com/) `format` method on duration objects? I can't find it anywhere in the docs and it doesn't seen to be an attribute on duration objects.

I'd like to be able to do something like:

```
var diff = moment(end).unix() - moment(start).unix();
moment.duration(diff).format('hh:mm:ss')

```

Also, if there are any other libraries which can easily accommodate this sort of functionality, I'd be interested in recommendations.

Thanks!

Answer: 
Use this plugin [Moment Duration Format](https://github.com/jsmreese/moment-duration-format).

Example:

```
moment.duration(123, "minutes").format("h:mm");

```
Based on [ni-ko-o-kin's answer](https://stackoverflow.com/a/44071876):

```
meassurements = ["years", "months", "weeks", "days", "hours", "minutes", "seconds"];
withPadding = (duration) => {
    var step = null;
    return meassurements.map((m) => duration[m]()).filter((n,i,a) => {
        var nonEmpty = Boolean(n);
        if (nonEmpty || step || i >= a.length - 2) {
            step = true;
        }
        return step;
    }).map((n) => ('0' + n).slice(-2)).join(':')
}

duration1 = moment.duration(1, 'seconds');
duration2 = moment.duration(7200, 'seconds');
duration3 = moment.duration(604800, 'seconds');

withPadding(duration1); // 00:01
withPadding(duration2); // 02:00:00
withPadding(duration3); // 01:07:00:00:00

```