将 date-fns 与 Firestore 服务器时间戳结合使用

问题描述 投票:0回答:0

我正在尝试使用 https://date-fns.org/ 在 React Native 中格式化我的 Firestore 服务器时间戳

我在文档中有这个示例函数

formatDistance(subDays(new Date(), 3), new Date(), { addSuffix: true })

我假设 formatDistance 有两个参数。我计算的日期以及当前日期。 (计算距离)

但是,使用时:

formatDistance(subDays(new Date(), item.created_at.toDate()), new Date(), { addSuffix: true, })

(item.created_at) - 是我的时间戳。

我收到错误消息:

Invalid time value
javascript date google-cloud-firestore timestamp
© www.soinside.com 2019 - 2024. All rights reserved.