在保存到Firestore之前,我可以获取serverTimestamp的值吗?

问题描述 投票:0回答:1

我需要在Unix Epoch格式12554327536中保存firebase的时间戳,这是自纪元以来的毫秒数。我不想使用Date().valueOf(),因为如果系统时间错误则不准确。我也不能将它存储为默认的December 25, 2020 at 12:02:50 PM UTC-5,因为我需要使用firebase的查询按日期排序。我这样使用它:

ref.where(`users.${userAuth.uid}`, '>', 0)
   .orderBy(`users.${userAuth.uid}`)

我在想,如果我先获得该值,然后转换它,然后保存它。然后我可以这样搜索和排序......或者有更好的方法来做到这一点吗?

timestamp google-cloud-firestore querying
1个回答
0
投票

在将数据写入服务器之前,无法获取实际的服务器端时间戳。

但是正在进行的工作是在提交数据之前公开客户端对时间戳的估计。见https://github.com/firebase/firebase-ios-sdk/pull/537

© www.soinside.com 2019 - 2024. All rights reserved.