【发布时间】: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);
}
它不起作用
【问题讨论】:
-
将两者都转换为 unix 时间戳,然后比较数字?