简体   繁体   中英

Firebase getting server Timestamp is returning a wrong value

I want to get Firebase Server current time as a timestamp but the value returned is wrong. The server returns a timestamp = 1535916111663 and if we convert this timestamp to date, I will be getting 30 March 50641 at 21:21:03

Note: I am using firebase Cloud function.

  exports.addPost = functions.region('europe-west1').https.onRequest((request, response) => {

  admin.database().ref('/.info/serverTimeOffset').once('value').then(function stv(data) {
          console.log(data.val() + Date.now());
    }, function (err) {
        return err;
   });
})

Whatever it is you're using to convert that timestamp into a date, it's interpreting the value as a number of seconds since the unix epoch. However, the value you're getting is actually measured in number of milliseconds since the unix epoch. You'll need to use a conversion tool that converts a timestamp in milliseconds to a date.

If you paste copy the value into this tool , it will automatically take the value as milliseconds. The value "1535916111663" that you provided above converts to "GMT: Sunday, September 2, 2018 7:21:51.663 PM"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM