我有一个小问题,我想知道哪个是最好的解决方案。 所以基本上我有一个带有属性“开始”和“结束”的表格。
我想将每一行放入数组中,其中“开始”日期是当天。 所以我的计划是使用 Axios、Sequelize 和 PostgreSQL 来做到这一点:
axios.get('http://localhost:3030/worktimes/', {
/*
params: {
Start: moment(new Date()) //here I just want to compare the actual date and not Date + Time
}
*/
})
.then(response => {
this.worktimes = response.data.data;
console.log(JSON.stringify(this.worktimes));
})
.catch((error) => {
console.log(error.data);
});
我正在使用 moment.js,但直到现在我还没有正确的想法如何在我的案例中使用这种智能。如果您也没有更好的主意,我只会获取数组中的所有内容,并尝试 trim “日期时间”的时间部分,但这似乎太复杂了。
最佳答案
将 moment.format()
应用于两个日期,您可以按字符串而不是按日期时间进行比较:
moment(new Date()).format('YYYY-MM-DD') === moment(postgreDate).format('YYYY-MM-DD')
关于javascript - 如何将 PostgreSQL 时间戳与 moment.js 进行比较并仅在日期基础上指定?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58201775/