1๐
โ
I solve it myself by doing like this,
callFirebase: function (){
let startdate = new Date(this.setSD+'T00:00:00');
startdate.setHours(startdate.getHours()+9);
let enddate = new Date(this.setED+'T00:00:00');
enddate.setHours(enddate.getHours()+9);
console.log(startdate.toISOString());
console.log(enddate.toISOString().split('.',1)[0]);
db.collection("study").
where("time", ">=", new Date(startdate.toISOString().split('.',1)[0])).
where("time", "<=", new Date(enddate.toISOString().split('.',1)[0])).
get().then(function (querySnapshot) {
querySnapshot.forEach(function (doc) {
// doc.data() is never undefined for query doc snapshots
console.log(doc.id, " => ", doc.data().time.toDate());
});
})
.catch(function (error) {
console.log("Error getting documents: ", error);
});
}
}
When declaring a new Date()
, date.toISOString()
is set by default in the where clause.
(such as 2020-01-21T00:00:00.000Z)
So I use split () to convert it to a string that fits the date constructor.
๐คfeelcard
Source:stackexchange.com