Javascript Firebase firestore到格式化日期的时间戳

Javascript Firebase firestore到格式化日期的时间戳,javascript,firebase,react-native,google-cloud-firestore,redux-firestore,Javascript,Firebase,React Native,Google Cloud Firestore,Redux Firestore,我正在做一个firebase项目,为了显示时间和实体,我得到的是时间戳。我正在做一个项目。如何将收到的时间戳转换为格式正确的日期。 这是时间戳: 我在this.props.time中有可用的时间,因此我尝试this.props.time.toDate(),但得到的是一个错误。 不变冲突:对象作为React子对象无效(发现时间:2019年11月26日星期二11:51:58 GMT+05:30(印度标准时间))如果从文档检索数据,可以执行以下操作: // time.toDate() convert

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

我在
this.props.time
中有可用的时间,因此我尝试
this.props.time.toDate()
,但得到的是一个错误。
不变冲突:对象作为React子对象无效(发现时间:2019年11月26日星期二11:51:58 GMT+05:30(印度标准时间))

如果从文档检索数据,可以执行以下操作:

// time.toDate()
convertDate(doc.data().time.toDate())

const convertDate = (date) => {
    // whatever formatting you want to do can be done here
    var d = date.toString()
    return d.substr(0, 21);
}
您可以创建一个新日期(time.seconds*1000+time.nanoseconds/1000000)然后按您想要的方式操作它。

您可以使用它来显示

{矩(yourTimestamp.toDate()).format( ****格式在上面的链接中 )}正确:
新日期(time.seconds*1000+time.nanoseconds/1000000)

不正确:
新日期(time.seconds*1000+time.nanoseconds/1000)

因为,

我想您可以将其转换为新日期(this.props.time.seconds*1000)我认为它转换正确,但显示时出错。你能提供你如何显示它的代码吗?@KishanBharda修复了它!我需要把它转换成字符串。我所做的是:新建日期(this.props.time.seconds*1000+this.props.time.nanoseconds/1000,).toLocaleDateString()我这样做后它工作了:新建日期(this.props.time.seconds*1000+this.props.time.nanoseconds/1000,).toLocaleDateString()