Skip to content
Advertisement

Firestore: Convert time object to timestamp

I am using vue.js for my e-commerce project. I want to set the sale time limit in the firestore collection.

ex)If user want to stop to sell his or her product at 15:00, user can input 15:00.

Now I could set the time object in my collection. But I want to convert it to timestamp.

How can I achieve it?

I set this.limit like this way in the template tag.

JavaScript

This is the script tag.

JavaScript

Advertisement

Answer

You don’t indicate if the timestamp should take the date of the day.

So let’s imagine you want to add a Timestamp for today at 15:00 to a Firestore document. Do as follows:

JavaScript

Note that firebase.firestore.FieldValue.serverTimestamp() “returns a sentinel used with set() or update() to include a server-generated timestamp in the written data” which will be calculated by the Firestore backend, not in the frontend.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement