I want to use Firebase to get the current time on server without writing to the database and then reading it.
Any one knows a solution to directly get a current time stamp from Firebase?
Yes there is! It doesn't matter if it is for IOS or for Android, you can write a frunction in Cloud Functions for Firebase which will be as easy as:
exports.currentTime = functions.https.onRequest((req, res) => {
res.send({"timestamp":new Date().getTime()})
})
You can host this in Cloud Function and get the server timestamp without user interaction.
For more informations on how to set/read a timestamp in a Firebase Real-time database, please see my answer from this post.
You have to write a firebase cloud function that calculates the time. Deploy that function on firebase. Whenever you request that function it will gives you the current time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With