【发布时间】:2020-08-23 07:38:31
【问题描述】:
我正在尝试使用new Date.getTime() 将当前时间保存在时间戳键内的临时对象中,并将其推送到全局可访问变量GLOBAL_VAR 内的数组中。
但是在我创建临时变量并打印它的值后,它显示时间戳是NaN 我不知道为什么我不能在对象中获取它(console.log(),结果如下所示)
另外,
handleOrderMessage函数在收到socket.io事件时调用不知道会不会影响new Date.getTime()函数,显示输出:
console.log("TEMP OBJECT IS", tempObject)
/*
{
id: "-909e-11ea-9ede-066a42ffe1ae",
price: "0.1",
quantity: "0.1",
side: "buy",
timestamp: NaN
}
*/
function handleOrderMessage(msg) {
let d = new Date();
console.log(d.getTime());
if (msg['status'] === "PLACED") {
//for buy
if (msg['orderSide'] === "Buy") {
let tempObject = {
side: "buy",
id: msg["OrderID"],
timestamp: d.getTime(),
quantity: parseFloat(msg["Quantity"].toFixed(4)).toString(),
price: parseFloat(msg["Price"].toFixed(4)).toString()
}
//pushing to the global orders with price from msg as key
if (tempObject.price in GLOBAL_VAR.bidOrdersPricesAsKey) {
GLOBAL_VAR.bidOrdersPricesAsKey[tempObject.price].push(tempObject);
} else {
GLOBAL_VAR.bidOrdersPricesAsKey[tempObject.price] = [tempObject]
}
console.log("GLOBAL VAR BUY ORDERS PRICES ASK KEY", GLOBAL_VAR.bidOrdersPricesAsKey)
console.log("TEMP OBJECT IS", tempObject)
}
}
【问题讨论】:
-
你的 sn-p 很难用。您应该添加必要的变量和函数调用。
-
...并删除所有不需要展示您的案例的内容
-
在这里工作正常:jsfiddle.net/7qgpcda1/1
-
这是一个非常大的文件..所以我没有展示它
标签: javascript html nan gettime