具有返回错误的简单函数:
错误: date.toLocaleDateString不是一个函数
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.问题是由BotBuilder体系结构引起的。
发布于 2017-08-17 01:01:26
Date.parse
返回一个数字。你在找new Date
。或者,如果time
已经是一个日期实例,只需使用time.toLocaleDateString()
(并确保它在每个函数调用中都是如此)!
function formatTime(time, prefix = "") {
return typeof time == "object" ? prefix + time.toLocaleDateString() : "";
}
发布于 2020-08-17 06:37:48
您可以使用
new Date(date).toLocaleDateString();
发布于 2021-04-21 12:43:21
在一个React应用程序中得到了这个错误,就这样解决了它:
{ (item.created instanceof Date) ? item.created.toLocaleDateString() : new Date(item.created).toLocaleDateString() }
https://stackoverflow.com/questions/45724975
复制相似问题