【问题标题】:Firestore Timestamp toDate() returns wrong UTC date?Firestore 时间戳 toDate() 返回错误的 UTC 日期?
【发布时间】:2021-10-16 15:14:58
【问题描述】:

我的 Firestore Emulator v9.16.0 中存储了以下日期:

正如您在屏幕截图中看到的,当我的鼠标悬停在EndDate 上时,它会显示正确的UTC 日期,即2021-08-13T11:09:58.000Z,但是当我发出以下代码时,它会返回错误的UTC 日期(@987654325 @):

在我的本地服务器 Node.js 中:

let maintConfigRef = db.collection("Configurations").doc("Maintenance");
let maintConfigDoc = await maintConfigRef.get();

if (maintConfigDoc.exists) {
     let maintConfigData = maintConfigDoc.data();
     let endDate = maintConfigData.EndDate.toDate().toJSON(); // Returns 2021-08-13T09:09:58.000Z
     console.log(endDate); // Output "2021-08-13T09:09:58.000Z"
};

这意味着它应该是...T11:09(如工具提示中所示)而不是...T09:09。任何人都知道它有什么问题,我还应该怎么做才能让它正确?提前致谢!

【问题讨论】:

  • 你试过toUTCString()吗?
  • @GiovanniEsposito Firestore 时间戳没有toUTCString(),但我尝试使用.toDate().toUTCString(),更糟糕的是:Fri, 13 Aug 2021 09:09:58 GMT,应该是Fri, 13 Aug 2021 19:09:58 GMT

标签: javascript node.js firebase google-cloud-firestore


【解决方案1】:

不知道是不是bug,但是安装firebase-tools 9.16.5之后问题就消失了:

npm install -g firebase-tools

【讨论】:

    猜你喜欢
    • 2011-09-26
    • 2020-11-02
    • 2015-10-23
    • 1970-01-01
    • 2012-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-02
    相关资源
    最近更新 更多