Moment.js:错误 ->UnhandledPromiseRejectionWarning

Moment.js : Error ->UnhandledPromiseRejectionWarning

我想知道我现在的时间戳是否等于或大于 ,但我遇到了一些错误

我的代码(有错误):

   {...}
  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