【发布时间】:2020-03-21 12:51:36
【问题描述】:
我正在做一个 firebase 项目,为了显示时间和实体,我得到的是时间戳。我正在做一个反应原生项目。如何将收到的时间戳转换为格式正确的日期。 这是时间戳:
我在this.props.time 有这个时间,所以我尝试了this.props.time.toDate(),但我得到的是一个错误。
Invariant Violation:Objects are not valid as a React child(found: Tue Nov 26 2019 11:51:58 GMT+05:30(Indian Standard Time))
【问题讨论】:
-
我猜你可以把它转换成类似
new Date(this.props.time.seconds * 1000) -
我认为它是正确的,但显示它时出错。你能提供代码你是如何显示它的吗?
-
@KishanBharda 已修复!我需要将其转换为字符串。我所做的是:new Date(this.props.time.seconds * 1000 + this.props.time.nanoseconds / 1000,).toLocaleDateString()
标签: javascript firebase react-native google-cloud-firestore redux-firestore