firebase - Firestore 如何保存日期?
问题描述
我最近发现了firestore.Timestamp
,所以我试图分配firestore.FieldValue.serverTimestamp();
给一个,但它没有用。相反,它说Type 'FieldValue' is not assignable to type 'Timestamp'
我会说这很奇怪。不应该serverTimestamp()
是 aTimestamp
而不是 aFieldValue
吗?firestore.Timestamp
如果不将时间戳保存到 Firestore ,目的是什么?有没有办法获得一个与时间戳兼容的服务器时间戳,firestore.Timestamp
或者我应该完全避免时间戳,并且只坚持firestore.FieldValue
我所有的日期?
解决方案
serverTimestamp()
只返回哨兵值,告诉 Firestore 服务器它应该使用服务器上的当前时间作为您尝试设置的字段的值。它不返回实际的 Timestamp 对象本身。
您使用它的原因是确保在服务器上设置的日期一致,而不是取决于用户设备上的时钟是否正确。
如果您想知道设备上的当前时间,只需使用语言或操作系统提供的本机日期/时间对象。
推荐阅读
- python - InvalidArgumentException:消息:二进制不是使用 GeckoDriver Firefox Selenium 和 Python 的 Firefox 可执行错误
- c# - 文件上传不发布/MVC
- javascript - 查询 Spotify 的 Web API 客户端凭证流
- visual-studio-code - 在 Windows 上的 VSCode 的 GLSL Lint 扩展上设置 Glsland 验证器路径的正确方法是什么(使用 WSL)
- html - 如何使用 Express 重定向到 html 页面,然后在该 HTML 文件中使用节点模块
- bash - 如果找到非唯一目录,则选择父目录
- flutter - 如何防止 ListTile 字幕属性扩展?
- r - 在 R studio 中拆分和写入 txt 文件时出错
- c - 使用 C 中的 fork 和 waitpid 函数对具有多个进程的文件中的字符、单词和行进行计数
- json.net - 当我调用 JsonConvert.DeserializeObject() 时,为什么将 JArray 分配给 var 失败?