Firebase 实时数据库 - DatabaseReference.push().getKey() 是一个时间戳
Firebase Real Time DB - DatabaseReference.push().getKey() is a TimeStamp
根据Documentation,下面的代码可以在实时数据库中使用push()将时间戳设置为节点的键。
public void uploadToDB(String s) {
databaseReference.push().setValue(s);
}
返回的key在我的push()下面,举个例子:
a) -MpfCu14jtIkEk28D3CB
b) -MpfCxv_Nzv3YJ87MfZH
我的问题是:
- 它们是时间戳吗?
- 如果是,我可以将它解码回可读的时间戳吗?
- are they timestamp?
不,那些推送的 ID 不是时间戳。但是,它包含一个时间组件。
正如 Michael Lehenbauer 在这篇 blog article 中提到的:
Push IDs are string identifiers that are generated client-side. They are a combination of a timestamp and some random bits. The timestamp ensures they are ordered chronologically, and the random bits ensure that each ID is unique, even if thousands of people are creating push IDs at the same time.
然后回答第二个问题:
- if yes, can I decode it back to readable timestamp?
如果你逆向工程,可能是的。请检查以下答案:
但不会指望那个。要根据时间组件进行排序,那么您应该添加类型为“timestamp”的 属性,正如我在以下 post:
中的回答中所解释的
根据Documentation,下面的代码可以在实时数据库中使用push()将时间戳设置为节点的键。
public void uploadToDB(String s) {
databaseReference.push().setValue(s);
}
返回的key在我的push()下面,举个例子: a) -MpfCu14jtIkEk28D3CB b) -MpfCxv_Nzv3YJ87MfZH
我的问题是:
- 它们是时间戳吗?
- 如果是,我可以将它解码回可读的时间戳吗?
- are they timestamp?
不,那些推送的 ID 不是时间戳。但是,它包含一个时间组件。
正如 Michael Lehenbauer 在这篇 blog article 中提到的:
Push IDs are string identifiers that are generated client-side. They are a combination of a timestamp and some random bits. The timestamp ensures they are ordered chronologically, and the random bits ensure that each ID is unique, even if thousands of people are creating push IDs at the same time.
然后回答第二个问题:
- if yes, can I decode it back to readable timestamp?
如果你逆向工程,可能是的。请检查以下答案:
但不会指望那个。要根据时间组件进行排序,那么您应该添加类型为“timestamp”的 属性,正如我在以下 post:
中的回答中所解释的