如何在Cloud Functions for Firebase中获取服务器时间戳? [英] How do I get the server timestamp in Cloud Functions for Firebase?
问题描述
我知道您可以在Web,iOS和android中获取服务器时间戳-但是Firebase的新Cloud Functions呢?我不知道如何在那里获得服务器时间戳?用例是我想在电子邮件到达时为其打上时间戳.
I know you can pull the server timestamp in web, ios, and android - but what about the new Cloud Functions for Firebase? I can't figure out how to get the server timestamp there? Use case is me wanting to timestamp an email when it arrives.
在网络上是Firebase.database.ServerValue.TIMESTAMP
On web it is Firebase.database.ServerValue.TIMESTAMP
但是在功能节点服务器界面中似乎不可用吗?
But that doesn't seem to be available in the functions node server interface?
我认为已经晚了,我可能在这里遗漏了重点...
I think it is late and I may be missing the point here...
编辑
我正在这样初始化
admin.initializeApp(functions.config().firebase);
const fb = admin.database()
然后,它被这样称呼.
Firebase.database.ServerValue.TIMESTAMP
但是,那是来自客户端集成.在功能上,Firebase不会像这样初始化.我已经尝试过
But, that is from a client side integration. On Functions, Firebase isn't initialized like this. I've tried
admin.database().ServerValue.TIMESTAMP
和
fb.ServerValue.TIMESTAMP
推荐答案
由于您已经在使用管理SDK,因此正确的语法是:
Since you're already using the admin SDK, the correct syntax is:
admin.database.ServerValue.TIMESTAMP
这篇关于如何在Cloud Functions for Firebase中获取服务器时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!