Retrieve ServerValue.Timestamp from Firebase in Android app, when data is sent(发送数据时,从 Android 应用中的 Firebase 检索 ServerValue.Timestamp)
问题描述
我想知道如何使用 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:发送数据时,从 Android 应用中的 Firebase 检索 ServerValue.Timestamp


- C++ 和 Java 进程之间的共享内存 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01