1 回答
TA貢獻1880條經驗 獲得超4個贊
根據您的數據庫結構,根據您startTime和endTime屬性的限制過濾數據,請使用以下查詢:
FirebaseFirestore rootRef = FirebaseFirestore.getInstance();
Query query = rootRef.collection("session")
.whereGreaterThanOrEqualTo("startTime", timeToCheck)
.whereLessThanOrEqualTo("endTime", timeToCheck);
如果不想平等,也可以使用以下代碼:
FirebaseFirestore rootRef = FirebaseFirestore.getInstance();
Query query = rootRef.collection("session")
.whereGreaterThan("startTime", timeToCheck)
.whereLessThan("endTime", timeToCheck);
因此,使用此代碼,您將能夠獲取session會話集合中開始和結束時間字段范圍內的所有對象。
編輯:
如果要檢查單個文檔,則需要使用另一個 if 語句。所以在你的實際中if (document.exists()){創建另一個看起來像這樣的:
Attendance attendance = document.toObject(Attendance.class);
Date startTime = attendance.getStartTime();
Date endTime = attendance.getEndTime();
if(timeToCheck.after(startTime) && (timeToCheck.before(endTime)) {
//Do what you need to do
}
其中timeToCheck是一個類型的對象Date,您需要檢查數據庫中的實際日期。
添加回答
舉報
