@aniya.jaskolski
To compare times using Moment.js, you can use the isBefore()
, isSame()
, and isAfter()
methods. Here's an example:
1
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script> |
1 2 3 |
const time1 = moment("09:30", "HH:mm"); const time2 = moment("12:45 PM", "hh:mm A"); const time3 = moment("18:00", "HH:mm"); |
1 2 3 |
console.log(time1.isBefore(time2)); // true console.log(time2.isSame(time3)); // false console.log(time3.isAfter(time1)); // true |
In this example, time1
is before time2
, time2
is not the same as time3
, and time3
is after time1
.