The isAfter()
method of the Moment.js time library is used to check if one time occurs later than another time. It returns a boolean that indicates if one time comes after another.
time1.isAfter(time2)
time1
and time2
: These are the times we want to compare. We compare time2
against time1
.The returned value is a boolean.
// require the moment moduleconst moment = require("moment")// create some dates and timeconst time1 = moment(new Date) // current date and timeconst time2 = moment([2010, 1, 14, 10, 25, 50, 125])const time3 = moment(1318781876406)const time4 = moment({hour: 20, minute: 20, second: 34})const time5 = moment([2022, 5, 17])const time6 = moment([2025, 4, 18])const time7 = moment().add(25, "seconds");// get the difference between one time and anotherconsole.log(time1.isAfter(time2)) // trueconsole.log(time2.isAfter(time3)) // falseconsole.log(time3.isAfter(time4)) // falseconsole.log(time4.isAfter(time5)) // falseconsole.log(time6.isAfter(time5)) // trueconsole.log(time7.isAfter(time2)) // true
require
the moment
library.isAfter()
method, we compare the times and print the results to the console.