具有返回错误的简单函数:
ERROR: date.toLocaleDateString is not a function
TypeError: date.toLocaleDateString is not a function
at FormatTime (../Src/rootdialog.js:87:58)
函数定义:
function FormatTime(time, prefix = "") {
var date = Date.parse(time);
return ((typeof time != "undefined") ? prefix + date.toLocaleDateString() : "");
}
函数接收 Date
对象作为输入,但即使使用 Date.parse()
显式转换为 Date
也无济于事。使用 Node.js 8.x。有什么解决办法吗?
P.S. Issue was caused by BotBuilder architecture.
最佳答案
Date.parse
返回一个数字。您正在寻找new Date
.或者,如果 time
已经是 Date 实例,只需使用 time.toLocaleDateString()
(并确保它确实存在于对函数的每次调用中)!
function formatTime(time, prefix = "") {
return typeof time == "object" ? prefix + time.toLocaleDateString() : "";
}
关于javascript - date.toLocaleDateString 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45724975/