SET1
SET1

Reputation: 29

How to get a timestamp from Firebase? Android

How can I get the current timestamp from Firebase? I found some methods, but they are all based on: write to database (ServerValue.TIMESTAMP), then read it. But it's not what I need, because it use additional resources. Also I've tried using System.currentTimestamp(), but its can be manipulated by the user. Is there any other ways? Maybe there is a cloud function to do so?

Upvotes: 2

Views: 797

Answers (1)

mark922
mark922

Reputation: 1167

You can write your own cloud function. Here is a very short example:

exports.currentTime = functions.https.onRequest((req, res) => {
    res.send({"timestamp":new Date().getTime()})
})

You can host this firebase cloud function and get the server timestamp which a user will not be able to affect.

Upvotes: 3

Related Questions