我遇到了一个我正在努力理解的问题。我只是想通过使用toDateString()将日期转换为更便于阅读的格式。然而,在这样做的过程中,我得到了一个“toDateString()不是函数”错误。
我可以使用toString()来完成此操作:
truncateDate() {
if (this.employee && this.employee.dob)
{
let birthDate = this.employee.dob;
console.log(birthDate); // 2011-06-12T05:00:00.000Z Prints to console
console.log(birthDate.toString());
}
}
但我无法执行toDateString():
truncateDate() {
if (this.employee && this.employee.dob)
{
let birthDate = this.employee.dob;
console.log(birthDate); // 2011-06-12T05:00:00.000Z Prints to console
console.log(birthDate.toDateString());
}
}
我错过了什么?