firebase.database.ServerValue.TIMESTAMP return an Object
firebase, firebase-realtime-database, javascript
Solution
This snippet from the Firebase documentation shows how to set a timestamp:
var userLastOnlineRef = firebase.database().ref("users/joe/lastOnline");
userLastOnlineRef.onDisconnect().set(firebase.database.ServerValue.TIMESTAMP);
To also have the value available in your code, you need to listen for the value:
userLastOnlineRef.on('value', function(snapshot) {
console.log(snapshot.val());
});
You'll see the value event fire twice (on the device that sets the value): once for the initial client-side estimate of the timestamp and once for the actual value from the server.
Problem
I'm working on a web project with Firebase. I call: ``` firebase.database.ServerValue.TIMESTAMP ``` and it returns: ``` {.sv: "timestamp"} ``` How will I get time of Firebase server with javascript?