gpt4 book ai didi

javascript - 我输入 future 时间戳时的日期无效

转载 作者:行者123 更新时间:2023-12-03 02:58:41 24 4
gpt4 key购买 nike

假设有一个 future 的时间戳日期。

var timestamp="1511858535000" //Future timestamp
var date=new Date(timestamp);
console.log(JSON.stringify(date));// this line give me Invalid Data

谁能帮我理解为什么?

最佳答案

您在评论中提到的时间戳工作正常,但您必须将其作为数字而不是字符串传递到 Date 构造函数中:

var timestamp = "1511858535000";
var date = new Date(Number(timestamp));
console.log(JSON.stringify(date));

关于javascript - 我输入 future 时间戳时的日期无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47507634/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com