Format hours, minutes and seconds with moment.js

momentjs

Solution

You are confusing format option with parsing option. Since your input string is not in ISO 8601 format, you have to specify format when parsing.

Here a working example for your use case:

var mom = moment('171054', 'HHmmss');
console.log(mom.format());
console.log(mom.format('HH:mm:ss'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.1/moment.min.js"></script>

Problem

I get this value from my backend service: `171054`. It represents `hh:mm:ss`. But when I use the formatting options from the docs it gives me back `00:00:00`. Things I've tried: ``` moment('171054').format('hh-mm-ss') moment('171054').format('HH-mm-ss') moment('171054').format('HH-MM-SS') ```

Original source