0

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 -->

enter image description here

What should I do?

tzrm
  • 513
  • 1
  • 8
  • 14
vaiana
  • 33
  • 6

1 Answers1

2

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);
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807