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.
Asked
Active
Viewed 3,999 times
0

Frank van Puffelen
- 565,676
- 79
- 828
- 807

Andrey Solera
- 2,311
- 2
- 26
- 51
-
May be this link might help: http://stackoverflow.com/a/36659507/5916727 – niraj Aug 07 '16 at 16:54
-
Since the final value for `ServerValue.TIMESTAMP` is determined on the Firebase servers, you cannot know the value before sending something to the server. This sounds like an [XY problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). It is typically easier to help if you describe what you are trying to accomplish, instead of starting from an assumed solution. – Frank van Puffelen Aug 07 '16 at 23:01
-
Im trying to add into a messagging app like a temporary item inside the adapter, because if the user tries to send and image it has to wait until its saved into the Firebase Database, so I add the temporary image and then when its saved by Firebase and pushed back into the app, I compare the timestamps and delete the temporary item of the adapter – Andrey Solera Aug 08 '16 at 02:55
1 Answers
1
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);

Community
- 1
- 1

Sahaj Rana
- 1,993
- 4
- 25
- 42
-
I don´t want to use the user cellphones timestamp, what I am using is the Firebase `ServerValue.TIMESTAMP`, but that gives me an object, from wich I need the long value of the timeStamp that has internally before send it to Firebase – Andrey Solera Aug 07 '16 at 16:43
-
-
1@andrea : for this you have to get from firebase database .you have to access from their using key. – Sachin Suthar Oct 20 '16 at 04:51