Firebase 为什么moment.js的日期提前了50年?

Firebase 为什么moment.js的日期提前了50年?,firebase,react-native,google-cloud-firestore,momentjs,Firebase,React Native,Google Cloud Firestore,Momentjs,使用矩格式化从firestore时间戳检索的日期。然而,这一日期至少要推迟一天,最多要推迟几个月。不管怎样,这一年都将减少50% 这是firestore的时间戳 编辑:以下是从lastMsg.seconds记录的内容: 1581372232 我在平面列表的renderItem中以秒为单位检索时间: renderItem={({ item, index }) => { return ( <Components.InboxItem

使用矩格式化从firestore时间戳检索的日期。然而,这一日期至少要推迟一天,最多要推迟几个月。不管怎样,这一年都将减少50%

这是firestore的时间戳

编辑:以下是从
lastMsg.seconds
记录的内容:
1581372232

我在平面列表的renderItem中以秒为单位检索时间:

 renderItem={({ item, index }) => {
        return (
            <Components.InboxItem
                title={item.withName}
                subtitle={item.lastMsg.seconds}
                img={item.withImg}
            />
        );
虽然我尝试了多种格式配置,但最接近准确的是
.startOf(“年份”)
。即使如此,日期仍显示为“2070年2月9日”。如果
.startOf()
更改为“月”、“日”或“小时”,则日期将更改为3月份的某个时间。如何将其修复为在firestore中显示日期?

查看我们可以获取JS
date
对象或使用
toMillis
方法获取毫秒

现在,这里给出了用于将时间戳转换为矩对象的简单的矩.js api

力矩(数)

现在,您可以对力矩对象应用如下格式:

力矩(数字)。格式(字符串)

错误日期的问题可能是由于同时使用了
utc
seconds
,并且没有将时间戳传递给
moment()

使用:

const props={
字幕:1581372232
};
常数日期=时刻
.unix(道具字幕)
.格式(“mm-DD-YYYY”);
控制台日志(日期)

你能在firestore的js代码中从控制台的时间戳屏幕截图旁边添加你检索到的实际数据吗?以秒为单位进行编辑问题是
时刻().utc().startOf('year')
给你2020/01/01,而
秒(…)
将该数据添加到日期中。unix纪元(1970/01/01)到2020年之间的年数是50年,因此2020年加上50年。
moment.unix(props.subtitle)
给了我
158137538
…然后呢?它在其他任何时刻都不起作用functions@Jim我假设
.format()
是隐含的
.unix()
返回矩的实例,而不是字符串。如何在firestore中使用toMillis()与react native firebase一起读取?我正在使用
firebase.firestoreFieldValue.serverTimestamp()
item.lastMsg编写
lastMsg
,它应该是firestore timestamp对象,您可以调用该对象上的函数。我假设react原生firebase lib也应该这样做。啊,最初我尝试
doc.get('time')。toMillis()
它不起作用。第二次尝试有效
const date = moment()
  .utc()
  .startOf('year')
  .seconds(props.subtitle)
  .format('MMMM DD YYYY');