Firestore Timestamp

Asked

Viewed 195 times

2

I’m doing a show with Firestore of a record.

When the date is saved in the database, it is saved as Timestamp (For example: Timestamp(Seconds=149914800, nanoseconds=0)), but when I open the plug editing tab, the date comes in the form of Timestamp, soon I need to convert to a normal date, I searched the documentation of Firestore and saw the function toDate() (that converts the Timestamp for a date), but when I went to use it, the console brings me the following error:

Uncaught (in Promise) Typeerror: data_nasc_.toDate is not a Function

I wanted to know how to solve it or else another way to make this conversion.

firebase.firestore().collection("usuario").doc(ocorrencia).get().then(usuario => {  

    data_nasc_ = usuario.data().Data_Nascimento.toDate();

}

1 answer

0

Good morning, apparently Data_nascimento.toDate(); it’s right, by mistake, you’re trying to give a toDate() again on data_nasc_.toDate, the nasc_data_isalready a date

  • 1

    good afternoon I forgot to see the answers, it turns out that the data was recorded in the database being a string and in it came as Timestamp(Seconds=149914800, nanoseconds=0), but it was not a real Firebase Timestamp, we changed how the date was recorded and worked toDate function normally

Browser other questions tagged

You are not signed in. Login or sign up in order to post.