Ale*_*ich 9 javascript string date node.js botframework
有简单的函数返回错误:
错误:date.toLocaleDateString不是函数
TypeError: date.toLocaleDateString is not a function
at FormatTime (../Src/rootdialog.js:87:58)
Run Code Online (Sandbox Code Playgroud)
功能定义:
function FormatTime(time, prefix = "") {
var date = Date.parse(time);
return ((typeof time != "undefined") ? prefix + date.toLocaleDateString() : "");
}
Run Code Online (Sandbox Code Playgroud)
函数接收Date
对象作为输入,但即使显式转换为Date
with Date.parse()
也无济于事.使用Node.js 8.x. 有解决方案吗
PS问题是由BotBuilder架构引起的.
Ber*_*rgi 12
Date.parse
返回一个数字.你在找new Date
.或者,如果time
已经是一个Date实例,只需使用time.toLocaleDateString()
(并确保它确实在每次调用函数时)!
function formatTime(time, prefix = "") {
return typeof time == "object" ? prefix + time.toLocaleDateString() : "";
}
Run Code Online (Sandbox Code Playgroud)
在 React 应用程序中遇到此错误,如下解决:
{ (item.created instanceof Date) ? item.created.toLocaleDateString() : new Date(item.created).toLocaleDateString() }
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
15128 次 |
最近记录: |