flutter datetime timestamp code example
Example 1: flutter date time to timestamp
DateTime currentPhoneDate = DateTime.now();
Timestamp myTimeStamp = Timestamp.fromDate(currentPhoneDate);
DateTime myDateTime = myTimeStamp.toDate();
print("current phone data is: $currentPhoneDate");
print("current phone data is: $myDateTime");
Example 2: flutter firebase timestamp
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;
}