【问题标题】:Date and Time format in Cloud FirestoreCloud Firestore 中的日期和时间格式
【发布时间】:2020-05-27 17:03:59
【问题描述】:

我将 Flutter 用于我的移动应用程序。它以这种格式将日期存储在 Cloud Firestore 中。

February 14, 2020 at 12:00:00 AM UTC+5

但是当我从 Cloud Functions 中保存日期时,它会存储为地图

{
_nanoseconds: 0,
_seconds: 1582743600
}

我希望云函数按照 Flutter 的格式存储日期。

我怎样才能做到这一点?

【问题讨论】:

  • “它以这种格式将日期存储在云 Firestore 中”-您确定它不只是将其存储为某种日期/时间类型,而当你把它转换成一个字符串?请注意,以相对难以解析的格式存储日期/时间数据对于任何其他应用程序(甚至对您的应用程序)都是非常不友好的。这就像将一个数字存储为“一千零一”。
  • 你解决了这个问题吗?

标签: typescript firebase google-cloud-firestore timestamp google-cloud-functions


【解决方案1】:

它将其存储为firebase.firestore.Timestamp (doc)。

您可以使用

导入Timestamp
import { Timestamp } from "@google-cloud/firestore";

【讨论】:

    猜你喜欢
    • 2020-12-06
    • 2020-03-21
    • 2011-09-25
    • 1970-01-01
    • 2020-02-23
    • 2019-10-30
    • 2023-02-12
    相关资源
    最近更新 更多