According to the Documentation, the below code can set a timestamp as the key of the node using push() in the Realtime Database.
public void uploadToDB(String s) {
databaseReference.push().setValue(s);
}
The returned key are below of my push(), as an example: a) -MpfCu14jtIkEk28D3CB b) -MpfCxv_Nzv3YJ87MfZH
My question is:
- are they timestamp?
- if yes, can I decode it back to a readable timestamp?
CodePudding user response:
- are they timestamp?
No, those pushed IDs are not timestamps. However, it contains a time component.
As Michael Lehenbauer mentioned in this blog article:
Push IDs are string identifiers that are generated client-side. They are a combination of a timestamp and some random bits. The timestamp ensures they are ordered chronologically, and the random bits ensure that each ID is unique, even if thousands of people are creating push IDs at the same time.
And to answer the second question:
- if yes, can I decode it back to readable timestamp?
If you reverse the engineering, probably yes. Please check the following answer:
But would not count on that. To have an order according to a time component, then you should add a property of type "timestamp", as explained in my answer from the following post: