I have a military time that I am trying to convert to a 12 hr am/pm format as shown below
console.log(moment("13:00", 'HH:mm').format('HH:mm a'));
console.log(moment("15:00", 'HH:mm').format('HH:mm a'));
But I am getting
13:00 pm
15:00 pm
as the output, when it should be 01:00 pm and 03:00 pm. Am I missing something on the code ?
moment docs are pretty clear on formatting - make sure to check them. "H" is 24 hour time. You want "h" instead (or hh for 0 prefixed).
console.log(moment("13:00", 'HH:mm').format('hh:mm a'));
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