If I will take date from the system (local date in UTC)
then, the problem occurs when the user changes the date, if I will use server date time then I can not able to send a message when I am offline, this application is developed in android using firebase real-time DB
Asked
Active
Viewed 86 times
0

Tanveer Munir
- 1,956
- 1
- 12
- 27

Jignesh
- 55
- 2
- 12
-
use ServerValue.TIMESTAMP – Ashvin solanki Mar 25 '19 at 13:41
-
did you solve your problem? – Ashvin solanki Mar 26 '19 at 06:19
-
no i have implemented this before but not working – Jignesh Mar 26 '19 at 06:38
-
not working ? any errors – Ashvin solanki Mar 26 '19 at 06:50
1 Answers
0
ServerValue.TIMESTAMP
public static final Map<String, String> TIMESTAMP
Also: Google Play services
A placeholder value for auto-populating the current timestamp (time since the Unix epoch, in milliseconds) by the Firebase Database
servers.
Example
Ref : https://stackoverflow.com/a/37868163/9909365
ref.addValueEventListener(new ValueEventListener() {
public void onDataChange(DataSnapshot dataSnapshot) {
System.out.println(dataSnapshot.getValue());
}
public void onCancelled(DatabaseError databaseError) { }
});
ref.setValue(ServerValue.TIMESTAMP);
Extra
Handling Latency
Server Timestamps
The Firebase Realtime Database servers provide a mechanism to insert timestamps generated on the server as data. This feature, combined with onDisconnect
, provides an easy way to reliably make note of the time at which a Realtime Database client disconnected
:
//Java
DatabaseReference userLastOnlineRef = FirebaseDatabase.getInstance().getReference("users/joe/lastOnline");
userLastOnlineRef.onDisconnect().setValue(ServerValue.TIMESTAMP);
//Kotlin
val userLastOnlineRef = FirebaseDatabase.getInstance().getReference("users/joe/lastOnline")
userLastOnlineRef.onDisconnect().setValue(ServerValue.TIMESTAMP)

Ashvin solanki
- 4,802
- 3
- 25
- 65