Firebase:在不写入数据库的情况下获取当前时间(IOS和ANDROID) [英] Firebase: Get current time without writing to the database (IOS and ANDROID)

查看:114
本文介绍了Firebase:在不写入数据库的情况下获取当前时间(IOS和ANDROID)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Firebase来获取服务器上的当前时间,而无需写入数据库然后再读取它.

I want to use Firebase to get the current time on server without writing to the database and then reading it.

有人知道直接从Firebase获取当前时间戳的解决方案吗?

Any one knows a solution to directly get a current time stamp from Firebase?

推荐答案

是的!无论是针对IOS还是Android,都可以在 Firebase的云函数中编写函数就像:

Yes there is! It doesn't matter if it is for IOS or for Android, you can write a frunction in Cloud Functions for Firebase which will be as easy as:

exports.currentTime = functions.https.onRequest((req, res) => {
    res.send({"timestamp":new Date().getTime()})
})

您可以将其托管在Cloud Function中,无需用户干预即可获取服务器时间戳.

You can host this in Cloud Function and get the server timestamp without user interaction.

有关如何在Firebase实时数据库中设置/读取时间戳的更多信息,请参阅此

For more informations on how to set/read a timestamp in a Firebase Real-time database, please see my answer from this post.

这篇关于Firebase:在不写入数据库的情况下获取当前时间(IOS和ANDROID)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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