我是否正确构造此Firestore查询?

时间:2019-05-05 23:59:30

标签: java android google-cloud-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 UTC-4 2019年5月5日上午12:00:00

示例2:

enter image description here

Log.d显示的是今天的正确日期/时间,并且我有许多安排了今天日期的文档。 这将返回具有当前日期的任何时间范围的所有文档。 任何帮助表示赞赏!

0 个答案:

没有答案