无法将HashMap用于子项中的TIMESTAMP

时间:2018-12-25 19:27:53

标签: java firebase firebase-realtime-database hashmap

我正在尝试新的时间戳记,并希望将其作为孩子插入。该怎么做?

我已经阅读了这篇文章 Write serverValue.timestamp as child in Firebase ..仍然不理解

我尝试将ServerValue.TIMESTAMP输入到子目录中,但未成功。这是我的代码:

Object timestamp = ServerValue.TIMESTAMP;
reference.child(String.valueOf(timestamp)).child(uid).child("Status").setValue(cA);

我已经读过了,

How to save the current date/time when I add new value to Firebase Realtime Database

我遵循其中的代码,无法正常工作->

enter image description here

我该怎么办?任何帮助谢谢:-)

1 个答案:

答案 0 :(得分:2)

ServerValue.TIMESTAMP只能写入一个值,不能用作数据库中的键。因此,如果要存储时间戳,则必须将其写为属性的值。如果要按时间顺序排列唯一键,请使用push()方法。

如此结合:

reference.push().setValue(ServerValue.TIMESTAMP);