0

Here is my code, where I push a newsObj to the realtime database

   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});
    });
   }

The outcome I want would be converting the long value I get from the db, something like this

news_timestamp_post_created: 
1535716975480

To 59 mins ago or when it exceeds 24hrs, it displays it by days then months as time goes on. I wouldn't want something like 3000mins ago or 120days ago to be displayed on my app.

My problem here is that I dont know how to convert this 1535716975480 to readable terms

Any small tip would be a great help. Thank you!

EDIT:

I have tried doing this

let elapsed = news.news_timestamp_post_created;//1535716975480 
console.log(new Date(elapsed)); 

which displayed 'Invalid date'

According to this SO link, the server timestamp is

"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"

I found out that, pic

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Justine M.
  • 359
  • 8
  • 24

0 Answers0