java - 我是否正确地构建了这个 firestore 查询?
问题描述
我需要获取指定日期/时间范围内的所有文件(都在同一天从 00:00:00 到 23:59:59)
我尝试了多个查询,文档中没有关于在不同时间查询同一日期的内容。大多数示例显示特定日期/时间,但我需要查询为今天安排的所有文档(动态)
private void loadList() {
Calendar c = Calendar.getInstance();
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
Date todayStart = c.getTime();
c.set(Calendar.HOUR_OF_DAY, 23);
c.set(Calendar.MINUTE, 59);
c.set(Calendar.SECOND, 59);
Date todayEnd = c.getTime();
Log.d(TAG, "this is the date/time for todayStart" + todayStart);
Log.d(TAG, "this is the date/time for todayEnd" + todayEnd);
mFirestoreDB.collection("events")
.whereGreaterThanOrEqualTo("dateScheduled", todayStart)
.whereLessThanOrEqualTo("dateScheduled", todayEnd)
.get()
.addOnCompleteListener(task -> {
if (task.isSuccessful()) {... ect
示例 Firestore 字段:dateScheduled 2019 年 5 月 5 日凌晨 12:00:00 UTC-4
示例 2:
Log.d 显示了今天的正确日期/时间,我有许多文件都安排了今天的日期。这应该返回今天日期的任何时间范围的所有文件。任何帮助表示赞赏!
解决方案
推荐阅读
- python - Matplotlib 条形图 - 每当代码重新运行时,x 轴分类变量都会发生变化(Numpy)
- reactjs - React Native - 一起使用 Immer.js 和 SetState 有问题吗?
- android - 在android中通过网络发送消息
- php - 如何使用 PHP 从表单在同一项目中发送 PUT 请求
- javascript - this.value 和 $(this).val() 有什么区别?
- mysql - 如何创建存储过程并在预定时间运行它(在 MYSQL 中)
- javascript - 为什么 Edge 中的 sessionStorage 与 Firefox/Chrome 不同,我该如何更改?
- python - 字典中字符串值的总和
- c - redis中run_with_period c宏背后的确切语法或规范是什么
- javascript - 比较日期时间与当前日期时间