1

When I console log my creation at the terminal it shows

"creation": Object { "nanoseconds": 420000000, "seconds": 1620290402, },

how can i format it into date and time so i can use it on frontend

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • See the linked question and more from https://www.google.com/search?q=%5Bgoogle-cloud-firestore%5D%5Bjavascript%5D+How+to+get+date+and+time+from+firebase.firestore.FieldValue.serverTimestamp() – Frank van Puffelen May 08 '21 at 20:50

2 Answers2

0

Here's a quick format that I've used in the past for Firebase to JS strings:

    //Firebase Timestamp Fix

    creation = new Date(creation.seconds * 1000);
    const formattedDate = creation.toLocaleDateString("en-US");
    const formattedTime = creation.toLocaleString('en-US', { hour: 'numeric', minute: 'numeric', hour12: true });
    const newDate = `${formattedDate} ${formattedTime}`;

akabin
  • 93
  • 8
0

The javascript doesn't know anything regarding the firebase time stamp.It simply gives you the object

So simply use toDate(). For further refernce check this source toDate() firestore