我想知道如何使用 Firebase 的 ServerValue.TIMESTAMP 方法,当我想在 Firebase 服务器上创建时间戳,然后将其检索到本地客户端.
I would like to know how to use Firebase's ServerValue.TIMESTAMP method, when I want to create a timestamp at the Firebase server, and then retrieve it to the local client.
在 Firebase 指南中,只有 javascript 对此案例有更详细的描述,但我很难弄清楚如何将其转换为我的 Android 应用程序.
In Firebase guides, only javascript has a more detailed description of this case, but I'm having a hard time figureing how to translate this in to my Android appliction.
提前致谢!
Firebase.ServerValue.TIMESTAMP 设置为 Map(包含 {.sv:"timestamp"}) 告诉 Firebase 用服务器的时间填充该字段.当该数据被读回时,它是实际的 unix 时间戳,它是一个 Long.
Firebase.ServerValue.TIMESTAMP is set as a Map (containing {.sv: "timestamp"}) which tells Firebase to populate that field with the server's time. When that data is read back, it is the actual unix time stamp which is a Long.
这样的事情会起作用:
Firebase ref = new Firebase("https://YOUR-FIREBASE.firebaseio.com");
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
Long timestamp = (Long) snapshot.getValue();
System.out.println(timestamp);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
ref.setValue(ServerValue.TIMESTAMP);
再举一个例子,你可以看看我对这个问题的回答:Android 聊天在 DataSnapshot.getValue() 上崩溃
For another example, you can see my answer to this question: Android chat crashes on DataSnapshot.getValue() for timestamp
这篇关于发送数据时,从 Android 应用中的 Firebase 检索 ServerValue.Timestamp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
“Char 不能被取消引用"错误quot;Char cannot be dereferencedquot; error(“Char 不能被取消引用错误)
Java Switch 语句 - 是“或"/“和"可能的?Java Switch Statement - Is quot;orquot;/quot;andquot; possible?(Java Switch 语句 - 是“或/“和可能的?)
Java替换字符串特定位置的字符?Java Replace Character At Specific Position Of String?(Java替换字符串特定位置的字符?)
具有 int 和 char 操作数的三元表达式的类型是什么What is the type of a ternary expression with int and char operands?(具有 int 和 char 操作数的三元表达式的类型是什么?)
读取文本文件并存储出现的每个字符Read a text file and store every single character occurrence(读取文本文件并存储出现的每个字符)
为什么我需要在 byte 和 short 上显式转换 char 原语Why do I need to explicitly cast char primitives on byte and short?(为什么我需要在 byte 和 short 上显式转换 char 原语?)