Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 现在如何将firebase.database.ServerValue.TIMESTAMP转换为相应的日期或时间?_Javascript_Firebase_Firebase Realtime Database - Fatal编程技术网

Javascript 现在如何将firebase.database.ServerValue.TIMESTAMP转换为相应的日期或时间?

Javascript 现在如何将firebase.database.ServerValue.TIMESTAMP转换为相应的日期或时间?,javascript,firebase,firebase-realtime-database,Javascript,Firebase,Firebase Realtime Database,这是我的代码,我将newsObj推送到实时数据库 addNewsObj(newsObj:News) { this.newsListRef.push(newsObj).then((snap) => { const key = snap.key; console.log(key); this.newsListRef.update(key, {news_timestamp_post_created: firebase.database.Serve

这是我的代码,我将newsObj推送到实时数据库

   addNewsObj(newsObj:News) {
    this.newsListRef.push(newsObj).then((snap) => {
      const key = snap.key;
      console.log(key);
      this.newsListRef.update(key, {news_timestamp_post_created: firebase.database.ServerValue.TIMESTAMP});
    });
   }
我想要的结果是转换我从db得到的长值,类似这样

news_timestamp_post_created: 
1535716975480
到59分钟前或超过24小时时,随着时间的推移,它按天显示,然后按月显示。我不想在我的应用程序上显示3000分钟前或120天前的东西

我的问题是,我不知道如何将1535716975480转换为可读的术语

任何小小的小费都会大有帮助。谢谢大家!

编辑:

我试过这样做

let elapsed = news.news_timestamp_post_created;//1535716975480 
console.log(new Date(elapsed)); 
哪个显示“无效日期”

据此,服务器时间戳为

"The doc says:

A placeholder value for auto-populating the current timestamp (time since the Unix epoch, in milliseconds) as determined by the Firebase servers"

我发现,

可能重复的请阅读我的更新问题,谢谢!那么基本上你想把时间戳转换成日期和时间吗?是的,我试着把它放在新的日期(经过的)里面,但它说这是一个无效的日期。请把你的尝试包括在你的问题里面(包括经过的实际值)