获取Firebase时间戳 [英] Get Firebase Timestamp
问题描述
我想知道如何从 ServerValue.TIMESTAMP
中直接从HashMap获取timeStamp的值。我知道,当将这个值发送到Firebase时,我会得到很长的值,但是我想在将它发送到Firebase之前得到这个值。
Okie所以经过一番研究,我发现在发送到数据库之前我们不能使用 ServerValue.TIMESTAMP
,因为
<设置为一个Map(包含{.sv:timestamp}),它告诉Firebase使用服务器的时间填充该字段。当这些数据被读回来的时候,它就是一个Long的实际的unix时间戳。
顺便说一下可以使用android自己的时间戳记并将其存储在Firebase中。
日历cc = Calendar.getInstance();
日期日期= cc.getTime();
// SimpleDateFormat format1 = new SimpleDateFormat(dd MMM);
SimpleDateFormat format2 = new SimpleDateFormat(yyyyMMddHHmmssSSS);
timestamp = format2.format(date);
I want to know how can I get the value of the timeStamp from the ServerValue.TIMESTAMP
, directly from the HashMap? I know that when that value is sent to Firebase I get the long value, but I want to get that long before send it to Firebase.
Okie so after some research I found that we cannot use ServerValue.TIMESTAMP
before sending it to database because
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.
By the way you can use android own timestamp and store it in Firebase.
Calendar cc = Calendar.getInstance();
Date date = cc.getTime();
// SimpleDateFormat format1 = new SimpleDateFormat("dd MMM");
SimpleDateFormat format2 = new SimpleDateFormat("yyyyMMddHHmmssSSS");
timestamp = format2.format(date);
这篇关于获取Firebase时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!