Firebase TIMESTAMP to date and Time

后端 未结 18 2583
温柔的废话
温柔的废话 2020-11-27 03:39

I am using firebase for my chat application. In chat object I am adding time stamp using Firebase.ServerValue.TIMESTAMP method.

I need to show the messa

18条回答
  •  日久生厌
    2020-11-27 04:05

    Firebase.ServerValue.TIMESTAMP is not actual timestamp it is constant that will be replaced with actual value in server if you have it set into some variable.

    mySessionRef.update({ startedAt: Firebase.ServerValue.TIMESTAMP });
    mySessionRef.on('value', function(snapshot){ console.log(snapshot.val()) })
    //{startedAt: 1452508763895}
    

    if you want to get server time then you can use following code

      fb.ref("/.info/serverTimeOffset").on('value', function(offset) {
        var offsetVal = offset.val() || 0;
        var serverTime = Date.now() + offsetVal;
      });
    

提交回复
热议问题