firestore.Timestamp.now();
I tried this way and it saves date as map.
nanoseconds: 388000000
seconds: 1570897877
nanoseconds and seconds type are number.
I want to save date as firestore timestamp using angular. I found duplicate questions without accepted answer.
If you want to add the current time as your Timestamp value in a Firestore document, you can you add it using FieldValue.serverTimestamp()
as Doug mentioned, as in the following example:
import * as firebase from 'firebase';
[ . . . ]
db.collection('times').add({time: firebase.firestore.FieldValue.serverTimestamp()});
Should you want to get a specific time, you can create a new Date object and add it to your Firestore using the function toDateString()
on it, as follows:
import * as firebase from 'firebase';
[ . . . ]
date = new Date('2018-11-16T09:48:51.137Z'); //sample date
this.db.collection('times').add({spec_time: this.date.toDateString()});
import * as firebase from 'firebase';
...
const data = {
createdAt: firebase.default.firestore.FieldValue.serverTimestamp(),
};
This code worked for me.
The important part was .default
from the root firebase object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With