Firebase 颤振火基时间戳
我想展示在今天或上周创建的帖子。我怎样才能做到这一点 这是我的firebase数据 这是我的问题Firebase 颤振火基时间戳,firebase,flutter,dart,google-cloud-firestore,Firebase,Flutter,Dart,Google Cloud Firestore,我想展示在今天或上周创建的帖子。我怎样才能做到这一点 这是我的firebase数据 这是我的问题 Future<List<Post>> getAllPost(Post lastFetched, int fetchLimit) async { List<Post> _postList = []; if (lastFetched == null) { _querySnapshot = await Firestore.instanc
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;
}
Future getAllPost(Post lastFetched,int fetchLimit)异步{
列表_postList=[];
if(lastFetched==null){
_querySnapshot=wait Firestore.instance
.收集(“员额”)
.orderBy(“喜欢”,降序:真)
.limit(fetchLimit)
.getDocuments();
}否则{
_querySnapshot=wait Firestore.instance
.收集(“员额”)
.orderBy(“喜欢”,降序:真)
.startAfterDocument(lastDocument)
.limit(fetchLimit)
.getDocuments();
}
如果(_querySnapshot.documents.length!=0){
最后文件=
_querySnapshot.documents[_querySnapshot.documents.length-1];
}
用于(DocumentSnapshot DocumentSnapshot在_querySnapshot.documents中){
Post-tekPost=Post.fromMap(documentSnapshot.data);
_postList.add(tekPost);
}
返回postList;
}
有一个库调用
用于创建模糊时间戳。(例如“5分钟前”)
var startfulldate=admin.firestore.Timestamp.fromDate(新日期(1556062581000));
db.collection('mycollection')
.where('start_time',,但我需要在我的firebase searchquery中进行配置。例如,如果一天前创建的post未获取getdocument,则获取文档。是否fetchLimit
时间以毫秒为单位?例如,今天将是158996642126
import 'package:timeago/timeago.dart' as timeago;
main() {
final fifteenAgo = new DateTime.now().subtract(new Duration(minutes: 15));
print(timeago.format(fifteenAgo)); // 15 minutes ago
print(timeago.format(fifteenAgo, locale: 'en_short')); // 15m
print(timeago.format(fifteenAgo, locale: 'es')); // hace 15 minutos
}
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)
});