【问题标题】:Cloud function saving different date on firestore云功能在firestore上保存不同的日期
【发布时间】:2021-03-08 18:55:40
【问题描述】:

这就是发生的事情:在云函数中,我有一个日期,我正在一个 Firestore 文档上写入,将日期转换为时间戳,如下所示:admin.firestore.Timestamp.fromDate(new Date(dateExample)) 当我在云功能上控制台记录日期时,它显示:Mon Mar 15 2021 00:00:00 GMT+0000 但在 Firestore 上,日期是 14 march 2020 21:00 UTC-3。 它减去 3 小时,这使得日期为 -1 天。 我怎样才能解决这个问题?我需要日期至少是同一天。

【问题讨论】:

    标签: firebase date google-cloud-firestore google-cloud-functions timezone


    【解决方案1】:

    在显示时,Firestore 控制台会将日期转换为您的时区,从而产生差异。但是,在后端,即在 Firestore 中,该值对应于您(或 Cloud Functions)编写的内容。

    在您的应用中,您可以决定处理时间戳的方式:显示其 GMT 值或使其适应用户的时区。

    【讨论】:

    • 嗨@RafaelHonda,您有机会查看建议的答案吗?
    猜你喜欢
    • 2021-04-05
    • 1970-01-01
    • 1970-01-01
    • 2019-08-26
    • 2018-05-09
    • 2022-12-20
    • 1970-01-01
    • 2018-03-21
    相关资源
    最近更新 更多