问题描述
我正在使用Firebase开发Web项目。我打电话:
firebase.database.ServerValue.TIMESTAMP
并返回:
$ p $ {。sv:时间戳}
如何使用JavaScript获取Firebase服务器的时间? b
展示了如何设置时间戳: 要在代码中还有可用的值,您需要监听值: 您将看到值事件触发两次(在设置该值的设备上):一次最初的客户端估计的时间戳,一次从服务器的实际价值。 I'm working on a web project with Firebase.I call: and it returns: How will I get time of Firebase server with javascript? This snippet from the Firebase documentation shows how to set a timestamp: To also have the value available in your code, you need to listen for the value: 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
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());
});
firebase.database.ServerValue.TIMESTAMP
{.sv: "timestamp"}
var userLastOnlineRef = firebase.database().ref("users/joe/lastOnline");
userLastOnlineRef.onDisconnect().set(firebase.database.ServerValue.TIMESTAMP);
userLastOnlineRef.on('value', function(snapshot) {
console.log(snapshot.val());
});