User 101
User 101

Reputation: 1431

How to convert seconds to HH:mm to HH:mm:ss in moment.js

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

Answers (2)

qiAlex
qiAlex

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

Satpal
Satpal

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

Related Questions