2
try {
  const docRef = await addDoc(collection(db, "question"), {
    title: writingTitle,
    createdAt: serverTimestamp(),
  });

If you write servertimestamp() when you write, the console window says {seconds=123123123, nanosecond=!@!@}} like this. How can I change this to Date on the web?

Frank van Puffelen
  • 499,950
  • 69
  • 739
  • 734
love
  • 21
  • 2
  • refer [here](https://stackoverflow.com/questions/34718668/firebase-timestamp-to-date-and-time) – gretal Dec 22 '21 at 06:34

1 Answers1

0

To convert a Firestore timestamp to a date, call toDate() on it after reading the value from the database. For more on this, see the reference docs.

There is no way to get the value before that/without reading it, as serverTimestamp() only generates a token value/sentinel that the database server recognizes as a signal to write the date/time.

Frank van Puffelen
  • 499,950
  • 69
  • 739
  • 734