Reputation: 2402
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.
Upvotes: 0
Views: 4026
Reputation: 2013
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);
Upvotes: 1