firebase - Flutter Firebase TimeStamp
问题描述
I wanna show post which created at today , or last week. How can I do this.
this is my query
Future<List<Post>> getAllPost(Post lastFetched, int fetchLimit) async {
List<Post> _postList = [];
if (lastFetched == null) {
_querySnapshot = await Firestore.instance
.collection("posts")
.orderBy("liked", descending: true)
.limit(fetchLimit)
.getDocuments();
} else {
_querySnapshot = await Firestore.instance
.collection("posts")
.orderBy("liked", descending: true)
.startAfterDocument(lastDocument)
.limit(fetchLimit)
.getDocuments();
}
if (_querySnapshot.documents.length != 0) {
lastDocument =
_querySnapshot.documents[_querySnapshot.documents.length - 1];
}
for (DocumentSnapshot documentSnapshot in _querySnapshot.documents) {
Post tekPost = Post.fromMap(documentSnapshot.data);
_postList.add(tekPost);
}
return _postList;
}
解决方案
var startfulldate = admin.firestore.Timestamp.fromDate(new Date(1556062581000));
db.collection('mycollection')
.where('start_time', '<=', startfulldate)
.get()
.then(snapshot => {
var jsonvalue: any[] = [];
snapshot.forEach(docs => {
jsonvalue.push(docs.data())
})
res.send(jsonvalue);
return;
}).catch( error => {
res.status(500).send(error)
});
推荐阅读
- java - 休眠 @Check 以确保在列中只出现一次特定值
- javascript - Jquery每个函数不在asp.net的gridview文本框中执行
- html - 如何将副标题与标题对齐?
- ios - Alamofire 的响应不正确?
- apache-kafka - 使用 Spark 结构化流式 Kafka 创建每小时快照
- excel - 下一个可用行和转置
- shell - 如何安装特定版本的 helm?
- c++ - c ++算法比较各种长度向量并隔离“唯一”,有点
- javascript - 多语言网站- 需要在每个页面上进行语言设置,如何避免这种情况?
- c# - 使用 NetOffice 在 Excel 中创建名称范围会引发 COMException