I am trying a new timestamp, and want to insert it as a child. How to do that?
I have read this post:
Write serverValue.timestamp as child in Firebase .. and still don't understand
I've tried to enter ServerValue.TIMESTAMP
into child and unsuccessful.
This my code:
Object timestamp = ServerValue.TIMESTAMP;
reference.child(String.valueOf(timestamp)).child(uid).child("Status").setValue(cA);
I've read this:
How to save the current date/time when I add new value to Firebase Realtime Database
I follow the code in it, and not work properly -->
What should I do?
The ServerValue.TIMESTAMP
can only be written into a value, it cannot be used as the key in the database. So if you want to store the timestamp, you will have to write it as the value of a property. If you want to have chronologically ordered, unique keys, use the push()
method.
So combined:
reference.push().setValue(ServerValue.TIMESTAMP);