如何在 Cloud Functions for Firebase 中获取服务器时间戳? [英] How do I get the server timestamp in Cloud Functions for Firebase?

查看:20
本文介绍了如何在 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()

然后,它被这样调用..

Then, it is being called like this..

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屋!

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