[英]how to validate the date after the current date in Nodejs?
我需要使日期验证在当前日期之后。 我试过这个:
Router.post('/home', [
check('due_date')
.isDate()
.isAfter(new Date.now())
.withMessage("The date should be in the future, after the current time."),
],(req, res) => {
const errors = validationResult(req);
if (!errors.isEmpty()){
return res.status(400).send({errors: errors.array()});
TPost.postT(req.body).then(message => {
return res.json(message);
}).catch((error) => {
return res.json(404, error);
});
});
但它不起作用,因为我得到了错误: TypeError: Date.now is not a constructor
。
尝试:
.isAfter(new Date())
在第 4 行
您可以使用“时刻”来验证、操作和比较日期。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.