Reputation: 1829
I'm fetching a document from firestore and I could already show it in the console too. This is what the data shows:
displayName: "Person1"
items:
itemAcquired: t {seconds: 1631084326, nanoseconds: 617000000}
itemName: "Book1"
[[Prototype]]: Object
I tried displaying the itemAcquired
in the screen but it display an "Invalid Date":
<ListItem>
<Typography>Item Acquired At : </Typography>
<ListItemText
primary={new Date(user.items?.itemAcquired).toLocaleDateString()}
/>
</ListItem>
Upvotes: 0
Views: 168
Reputation: 1358
JavaScript Date doesn't know about firestore timeStamp object, you can use toDate() function along with toDateString()
const date = itemAcquired.toDate().toDateString()
Also you can try
new Date(temAcquired.seconds * 1000).toUTCString()
Upvotes: 1