Reputation: 1431
Suppose I have a time as 13:45
.
Now I want to convert this into 13:45:00
using moment.js.
I am doing
moment('13:45').format('h:m:s');
but it is not working.
Upvotes: 1
Views: 2255
Reputation: 4346
You need to add second parameter to let moment know the format of your passed date
moment('13:45', 'HH:mm').format('h:m:s')
or
moment('13:45', 'HH:mm').format('HH:mm:ss')
Upvotes: 2
Reputation: 133403
Use moment
constructor to create a object then use format()
console.log(moment('13:45', 'HH:mm').format('HH:mm:ss'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
Upvotes: 2