【发布时间】:2019-10-31 05:32:51
【问题描述】:
使用带有 Cloud Scheduler 的 CloudFunctions 从 Firestore 获取时间戳数据。然后我想比较时间戳数据。 具体来说,Cloud Functions 使用 Cloud Scheduler 在每天 12:00 执行。我想检查firestore的时间戳在执行时是否超过10天。如果超过,则执行特定流程。
如果我可以在从 Firestore 获得的时间戳上加上 10 天,那将是可比的,但它不起作用。具体来说,我尝试使用 toDate() 将时间戳转换为日期,并尝试添加 10 天。
【问题讨论】:
-
Timestamp 返回 {seconds: number, nanoseconds: number} 的对象。取决于您需要的精度,但创建日期的一种方法是
new Date(timestamp.seconds*1000) -
不要描述您在代码中尝试的内容,而是添加实际的minimal code that reproduce the problem to your question。这将使某人更有可能发现您出错的地方。另见how to create a minimal, complete, verifiable example。
标签: firebase google-cloud-firestore google-cloud-functions