Nicholas Santi
Nicholas Santi

Reputation: 47

How to get timestamp format data from Firestore Node.js

I save dates in a format like

this

in Cloud Firestore

How do I get it in Date format in Node.js?

Upvotes: 2

Views: 2592

Answers (1)

Waelmas
Waelmas

Reputation: 1962

When you get timestamps from Firestore they are of the following type:

enter image description here

To convert this into a Node.js timestamp you can use the .toDate() function.

For example, for a document like the following:

enter image description here

We can use something like:

db.collection('[COLLECTION]').doc('[DOCUMENT]').get().then(function(doc) {
  console.log(doc.data().[FIELD].toDate());
});

and the output will be like:

2019-12-16T16:27:33.031Z

Upvotes: 4

Related Questions