-1

I want to add a timestamp of a data entry creation, example:

myRef.child("uid").setValue(data);
//add timestamp to the same path myRef.child("uid").setValue(<timestamp here>)

What would be the best timestamp, so that it will be independent of any time zone? (For example if a user's phone clock is set to the wrong time)

I did see this article from Firebae docs: Timestamp, but can't figure how to use it.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
pileup
  • 1
  • 2
  • 18
  • 45
  • Check also **[this](https://stackoverflow.com/questions/43584244/how-to-save-the-current-date-time-when-i-add-new-value-to-firebase-realtime-data)** out. – Alex Mamo Nov 23 '18 at 09:48

2 Answers2

1

Use the value placeholder firebase.database.ServerValue.TIMESTAMP to update a value with the current clock time on the server at the time of the write, as seen by the server. It's a token value that means nothing on the client but has a special meaning on the server when it's written.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
0

inside Firebase Functions transform the timestamp like so:

timestampObj.toDate() timestampObj.toMillis().toString() documentation here https://firebase.google.com/docs/reference/js/firebase.firestore.Timestamp

ANKIT MISHRA
  • 558
  • 4
  • 13