firebase.database.ServerValue.TIMESTAMP return an Object

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.


It's expected that you will use firebase.database.ServerValue.TIMESTAMP in data that's written to the Firebase database. It's a placeholder for the actual time on the server and will be replaced when the server receives and writes the data.

You will see the actual timestamp value when you read the data from the database or when any listeners you have might have already configured fire (for child_added, child_changed, or value events etc.).

It's explained in the documentation here:

{TIMESTAMP: non-null Object}

A placeholder value for auto-populating the current timestamp (time since the Unix epoch, in milliseconds) as determined by the Firebase servers.