Is there a way to obtain the server time without having to first set it? For example, I can simply do:
curl -X PUT -d '{".sv": "timestamp"}' https://SampleChat.firebaseIO-demo.com/servertime.json
which will return the server time, but this sets the value servertime within my firebase instance. I should note that I'm using the REST API.
You can retrieve the server time without writing it by using .info/serverTimeOffset:
var fbRef = new Firebase(URL);
var getServerTime = (function(ref) {
    var offset = 0;
    ref.child('.info/serverTimeOffset').on('value', function(snap) {
       offset = snap.val();
    });
    return function() {
       return Date.now() + offset;
    }
})(fbRef);
var now = getServerTime();
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With