I am trying to format a String into a 24 hour format using moment JS at the moment I am not getting the expected output, the below explains it in more detail:
How I am coverting
var testFormat = moment("9:00","HH:mm:ss");
I was hoping this would output:
09:00:00 (24 Hour format)
But for some reason is does not convert just the date, this is outputing the following:
1471507200000
You are using it wrong. You can provide a format as the second argument to moment. So in your case it would be:
var myMoment = moment("9:00","H:mm");
To get the moment
. Now you can format it the way you want:
myMoment.format("HH:mm:ss");
DEMO
moment("13:15:00", "h:mm:ss").format("hh:mm A"); it will give 12 hrs format
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With