【问题标题】:Problem with compare date now with date from MySQL [Angular]现在将日期与 MySQL [Angular] 中的日期进行比较的问题
【发布时间】:2019-09-26 11:06:17
【问题描述】:

我尝试比较 MySQL:DATENOW 中的日期,并将它与现在的日期进行比较。

这是我的功能

  getReports(onSuccessCallback: Function) {
    this.http.getReports(Globals.userID).subscribe(data => {
      data.map((report) => {
        const nowDay = new Date().toLocaleDateString();
        report.deadLine = new Date(report.deadLine).toLocaleDateString();
        if (report.deadLine === nowDay) {
          console.log(true);
        }
      });
      onSuccessCallback(data);
    }, error => {
      console.log(error);
    });
  }
}

当我这样做时工作正常,并采取什么等于和控制台为真,但问题是如果日期已经过去,我尝试控制台为真 我试试:

if (report.deadLine < nowDay){
          console.log(true);
        }

它不起作用

【问题讨论】:

标签: mysql angular date


【解决方案1】:

你必须更改代码集

  const nowDay = new Date().toLocaleDateString();
            report.deadLine = new Date(report.deadLine).toLocaleDateString();
           if (report.deadLine < nowDay){
          console.log(true);
        }

到这里

 const nowDay = new Date();
        report.deadLine = new Date(report.deadLine);
        if (report.deadLine < nowDay){
          console.log(true);
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多