0

I'm fetching a Timestamp object from Firebase/Firestore. I want to present the date in a dd/MM/YYYY hh:mm format.

I've tried to convert it to JS date and use toString(), but I can't figure out how can I set the format:

const dateString = doc.data()["date"].toDate().toString();

Does anybody have an idea?

Doug Stevenson
  • 236,239
  • 27
  • 275
  • 302
F.SO7
  • 407
  • 4
  • 17

1 Answers1

1

The Firestore library doesn't have any facilities to format a timestamp. However, since you're able to convert it to a JavaScript Date object using toDate(), you can then use libraries such as momentjs to format the date in very flexible ways. If you can't use that, you can format it yourself using Date's own instance methods to get the calendar components out of it.

Doug Stevenson
  • 236,239
  • 27
  • 275
  • 302