如果我有两个Javascript日期对象,我怎样才能看到我的selectedDate是否至少在未来一小时?防爆。如果是3PM,则selectedDate需要至少下午4点
var selectedDate = //somedatetime object
var currentDate = new Date(); // includes current time
if (selectedDate is before currentDateTime + 1 hour) {
// return false
}
答案 0 :(得分:0)
日期的值以毫秒为单位。所以看看它是否落后1小时毫秒(3600000)。
if (+selectedDate < +currentDateTime + 3600000) {
//more than an hour has passed
}