Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase: Get current time without writing to the database (IOS and ANDROID)

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?

like image 684
data Avatar asked Mar 06 '23 17:03

data


2 Answers

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.

like image 135
Alex Mamo Avatar answered Apr 27 '23 06:04

Alex Mamo


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.

like image 44
Raj Avatar answered Apr 27 '23 06:04

Raj