Firebase Firestore 时间戳到格式化日期

For*_*kie 3 javascript firebase react-native google-cloud-firestore redux-firestore

我正在研究一个 firebase 项目,为了显示时间和实体,我得到的是时间戳。我正在做一个 React Native 项目。如何将接收到的时间戳转换为格式正确的日期。这是时间戳:

在此处输入图片说明

我有这个时间可用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))

小智 6

您可以创建一个Date 对象new Date(time.seconds * 1000 + time.nanoseconds/1000000)然后按照您想要的方式操作它。