Javascript 从cloud firestore中拉出时,时间戳显示为字符串

Javascript 从cloud firestore中拉出时,时间戳显示为字符串,javascript,google-cloud-firestore,Javascript,Google Cloud Firestore,我已经将一段时间戳数据提取到一个html数据属性中 然后我想用它来填充一个日期表单字段,该字段将出现在模式弹出窗口中 然而,当尝试使用toDate时,我得到了错误 未捕获类型错误:moderationDate.toDate不是函数 为了进行测试,我使用了警报来检查变量moderationDate上的值和数据类型。我可以看到数据以字符串形式存储在html数据属性中 <td data-moderateModerationDate="'+student.UnitGrades.IT6.Modera

我已经将一段时间戳数据提取到一个html数据属性中

然后我想用它来填充一个日期表单字段,该字段将出现在模式弹出窗口中

然而,当尝试使用toDate时,我得到了错误

未捕获类型错误:moderationDate.toDate不是函数

为了进行测试,我使用了警报来检查变量moderationDate上的值和数据类型。我可以看到数据以字符串形式存储在html数据属性中

<td data-moderateModerationDate="'+student.UnitGrades.IT6.Moderate.ModerationDate+'" >table data item</td> \

let moderationDate = $(this).attr("data-moderateModerationDate");

alert(moderationDate);
alert(typeof moderationDate);
警报1输出-时间戳秒=0,纳秒=0 警报2输出-字符串
有人能告诉我为什么这是一个字符串数据类型,而不是原始时间戳吗?

只能存储字符串,所以你不能期望在其中放入任何内容,也不能期望得到确切的内容。当您使用字符串连接添加字符串时,浏览器会在存储它时将其转换为字符串。我建议尝试另一种方法来存储此值。

$this.attrdata-mediateModerationDate;是字符串而不是时间戳