我想知道我的时间戳现在是否等于或大于,但我得到一些错误
我的代码(有错误):
{...}
exports.validaforgotpass = async (req, res) => {
{...}
const results = await mysql.execute(query, [req.headers.email]);
var newDateObj = moment(now).toDate();
newdate = moment(newDateObj).format('YYYY-MM-DD hh:mm:ss');
validDate = moment(results[0].codmailtime).format('YYYY-MM-DD hh:mm:ss');
try {
if (results.length < 1) {
return res
.status(401)
.send({ user:{message: "Email não consta em nossa base de dados" }});
}
else if(req.headers.token = results[0].codmailtemp && newdate.isSameOrAfter(validDate)){
return res.status(200).send({ user:{message:'Codigo correto',cod:results[0].codmailtemp}});
}
else{
return res.status(401).send({ user:{message:'Codigo incorreto',cod:results[0].codmailtemp}});
}
} catch {return res.status(500).send({ user:{message:messsage.error}});}
} catch {return res.status(500).send({ user:{message: error.message}});}
};
有人知道为什么,以及如何修复它吗?
我没有把变量作为日期对象。我修改了我的代码如下,它运行得很好。
var now = new Date();
const moment= require('moment')
try{
newdate = moment(now).format('YYYY-MM-DD hh:mm:ss');
validDate = moment(results[0].codmailtime).format('YYYY-MM-DD hh:mm:ss');
console.log(validDate > newdate)
}catch{
{return res.status(500).send({ user:{message: error.message}});}
}
try {
if (results.length < 1) {
return res
.status(401)
.send({ user:{message: "Email não consta em nossa base de dados" }});
}
else if(req.headers.tok