Senthil
Senthil

Reputation: 1101

convert string time to moment in javascript

I would like to know is it possible to convert string time to moment in javascript. I am using moment.js

var str="11:00" // convert this to moment()

I tried

var result = moment(str); //not working

Upvotes: 0

Views: 1563

Answers (2)

Harish Shisode
Harish Shisode

Reputation: 819

you can do it as follows

moment(str, 'h:mm a')

for more information please refer https://momentjs.com/docs/#/parsing/

Upvotes: 0

StepUp
StepUp

Reputation: 38114

You can use format method:

moment('11:00','h:mm a').format('h:mm a');

More info can be read here.

Upvotes: 1

Related Questions