我正在尝试比较像这样的各种Date元素2个日期元素表示日期格式,但无法对两者进行比较,导致显示">core.js:6237错误类型错误:newticketList.createdAt.toDateString不是函数"。以及其他任何函数,如getDate或getMonthps.:我已经搜索到它不能被识别为Date格式,但在这种情况下,我该如何绕过它?
ticketList: Array<Ticket>;
let dateTime = new Date()
(…(
this.ticketList = this.ticketList.filter(
newticketList => (newticketList.createdAt.toDateString() != dateTime.toDateString()))
createdAt
不包含名为toDateString
的方法
this.ticketList.map(
newticketList => console.log(newticketList.createdAt));
检查你从中得到了什么
我完成了。尽管两个变量在内部都设置为Date,但它们被处理为String所以解决方案不是:
newticketList =>
(newticketList.createdAt.toDateString() != dateTime.toDateString()))
我们得到这个:
newticketList =>
(new Date(newticketList.createdAt).toDateString() != dateTime.toDateString()))