Sometimes, we want to get am pm from the date time string using moment.js and JavaScript.
In this article, we’ll look at how to get am pm from the date time string using moment.js and JavaScript.
How to get am pm from the date time string using moment.js and JavaScript?
To get am pm from the date time string using moment.js and JavaScript, we use the 'A'
format code.
For instance, we write
console.log(
moment("Mon 03-Jul-2022, 11:00 AM", "ddd DD-MMM-YYYY, hh:mm A").format(
"hh:mm A"
)
);
to call format
on a moment object with "hh:mm A"
to return a time string with the hours and minutes along with am or pm at the end with 'A'
.
Conclusion
To get am pm from the date time string using moment.js and JavaScript, we use the 'A'
format code.