Sometimes, we want to compare two times with Moment.js and JavaScript.
In this article, we’ll look at how to compare two times with Moment.js and JavaScript.
How to compare two times with Moment.js and JavaScript?
To compare two times with Moment.js and JavaScript, we can parse times with moment.
For instance, we write
const beginningTime = moment("8:45am", "h:mma");
const endTime = moment("9:00am", "h:mma");
console.log(beginningTime.isBefore(endTime));
to call moment with the times we want to compare.
Then we check if beginningTime is before endTime with isBefore.
Conclusion
To compare two times with Moment.js and JavaScript, we can parse times with moment.