将时间添加到Firestore serverTimestamp() [英] Adding time to Firestore serverTimestamp()

查看:57
本文介绍了将时间添加到Firestore serverTimestamp()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在不使用云功能的情况下为服务器时间戳添加时间?

Is there a way to add time to a server timestamp without using cloud functions?

我要从面板更新时间戳,并让用户方检查时间戳是否大于当前时间.我还希望面板用户能够设置添加时间,因此在用户端执行逻辑不是最佳解决方案.

What I want is to update a timestamp from a panel, and have the user side check if the timestamp is greater than the current time. I also would like for the panel user to be able to set the amount of time to add, so doing the logic on the user side is not an optimal solution.

示例:

document.set({ validTo: firestore.FieldValue.serverTimestamp() + 5000 });

推荐答案

您无法在客户端上的服务器时间戳上执行日期数学运算. FieldValue值只是在服务器上解释的令牌.如果要使用Google服务器时间进行日期数学运算,则必须在Google服务器上运行该逻辑.

You can't perform date math on server timestamps on the client. FieldValue values are just tokens that are interpreted on the server. If you want to do date math using Google server time, you'll have to run that logic on Google servers.

如果绝对需要在客户端上执行此操作,则必须在一个操作中写入时间戳,然后在第二个操作中读回文档,然后在第三次操作中将修改后的日期值写回到文档

If you absolutely need to do this on the client, you'll have to write the timestamp in one operation, then read the document back in a second operation, then write the modified date value back to the document in a third operation.

这篇关于将时间添加到Firestore serverTimestamp()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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