Waseem Ahmed
Waseem Ahmed

Reputation: 419

Get firebase/firestore SERVERTIME and convert to date (month and day)

I am trying to get the server time either from Firebase or Firestore. I have tried ServerValue.TIMESTAMP but it is not pulling a value when i try to view in Log.d("Time", "${SERVERValue.TIMESTAMP}").

What i would like to do is eventually convert this to a simple date i.e. month and day so that i can store the future expiry date of an account. e.g. take today's date, add 31 days and in the future once the date is reached lock the user out of the account if not renewed.

How would I retrieve the original stored date, convert to date and then do a logical check to see if expired or not?

Upvotes: 1

Views: 539

Answers (1)

samthecodingman
samthecodingman

Reputation: 26226

ServerValue.TIMESTAMP is a constant that is used as a placeholder value that once uploaded to the server, is replaced with the server time.

Based on the sensitivity of setting an account's expiry date, I would not handle this on your client and instead use one of the Admin SDKs on a trusted server or use Cloud Functions.

However, to get the current server time, you can make use of Kronos and the time.google.com NTP server (You can also use time1, time2, time3 and time4 appended with .google.com).

Upvotes: 2

Related Questions