Ad

JavaScript Date To Firestore Timestamp

I have a form with datepicker which stores the date like "1559389274032".

Is there a way to convert this to a firestore timestamp?

Ad

Answer

Try something like this:

var myDate = firebase.firestore.Timestamp.fromDate(new Date());

Where new Date() would be your timestamp constructor.

Also I'm 99% sure that you dont even need it, this should save the value as a date, just make sure you dont convert it to a string on your end.

ref.update({ created_at: new Date() })
Ad
source: stackoverflow.com
Ad