firebase.database.ServerValue.TIMESTAMP返回一个Object [英] firebase.database.ServerValue.TIMESTAMP return an Object

查看:121
本文介绍了firebase.database.ServerValue.TIMESTAMP返回一个Object的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Firebase开发Web项目。
我打电话:

  firebase.database.ServerValue.TIMESTAMP 

并返回:

$ p $ {。sv:时间戳}

如何使用JavaScript获取Firebase服务器的时间? b

解决方案

展示了如何设置时间戳:

pre $ > var userLastOnlineRef = firebase.database()。ref(users / joe / lastOnline);
userLastOnlineRef.onDisconnect()。set(firebase.database.ServerValue.TIMESTAMP);

要在代码中还有可用的值,您需要监听值:

  userLastOnlineRef.on('value',function(snapshot){
console.log(snapshot.val());
});

您将看到值事件触发两次(在设置该值的设备上):一次最初的客户端估计的时间戳,一次从服务器的实际价值。

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?

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.

这篇关于firebase.database.ServerValue.TIMESTAMP返回一个Object的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆