[英]Firebase firestore query by datetime show different results depending of the timezone of the phone Flutter
在 firebase firestore 上保存和查询 bettwing 日期时,我遇到时区问题。 我想保存日期而不关心时区,就像 (2022-12-31 00:00:00.000),但是当我在客户端执行此操作时,它会根据时区在不同的日期保存,并查询结果不同的数据也。
我如何独立于时区执行此操作? 我的意思是,如果用户使用的是 UTC+4 或 UTC-4,保存时它不会更改日期或时间,只需将 (2022-12-31 00:00:00.000) 保存在 firestore 数据库中? 不知何故,我不明白它是根据我猜的本地时区查询和保存的。
提前致谢。
firebase
添加数据时使用Firebase 的时间戳时间戳表示独立于任何时区或日历的时间点,在 UTC 纪元时间中以纳秒分辨率表示为秒和秒的分数。 它使用 Proleptic Gregorian Calendar 编码,该日历将 Gregorian 日历向后扩展到第一年。 它的编码假设所有分钟都是 60 秒长,即闰秒被“涂抹”,因此不需要闰秒表来解释。
_firestore
.collection('post')
.add({
'text': postText,
'created': FieldValue.serverTimestamp() // 👈 This timestamp is independent of the timezone
});
_firestore.
.collection('post')
.orderBy('created', descending: false) // 👈 Data will be same irrespective of access point
.snapshots()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.