Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从Flatter中的firebase检索时间时出错?_Firebase_Flutter_Dart_Google Cloud Firestore - Fatal编程技术网

从Flatter中的firebase检索时间时出错?

从Flatter中的firebase检索时间时出错?,firebase,flutter,dart,google-cloud-firestore,Firebase,Flutter,Dart,Google Cloud Firestore,大家好,我正在尝试检索firebase中存储的时间和日期,但我返回的时间值以毫秒为单位。有人能帮我解决这个问题吗。 这是我的密码 class _UserListState extends State<UserList> { final databaseReference = Firestore.instance; getList() async { databaseReference .collection("bookings")

大家好,我正在尝试检索firebase中存储的时间和日期,但我返回的时间值以毫秒为单位。有人能帮我解决这个问题吗。

这是我的密码

class _UserListState extends State<UserList> {
  final databaseReference = Firestore.instance;

  getList() async {
    databaseReference
        .collection("bookings")
        .getDocuments()
        .then((QuerySnapshot snapshot) {
      return snapshot.documents;
    });
  }

  @override
  Widget build(BuildContext context) {
    return 
      Scaffold(
        appBar: AppBar(title: Text(widget.isDelete? "Delete User": "User List"),backgroundColor: Colors.indigo,),
        body: ListView(
          padding: EdgeInsets.all(12.0),
          children: <Widget>[
            SizedBox(height: 20.0),
            StreamBuilder<QuerySnapshot>(
                stream: databaseReference.collection('bookings').snapshots(),
                builder: (context, snapshot) {
                  if (snapshot.hasData) {
                    return Column(
                      children: snapshot.data.documents.map((doc) {
                        print(doc.data);
                        return ListTile(
                          title:  RichText(
                            text: TextSpan(children: [
                              TextSpan(text: "Boat_id : ${doc.data["boat_id"]}\n"),
                              TextSpan(text: "Grand Total : ${doc.data["grand_total"]}\n"),
                              TextSpan(text: "Number of Passengers : ${doc.data["no_of_passengers"]}\n"),
                              TextSpan(text: "Promo code : ${doc.data["promo_code"]}\n"),
                              TextSpan(text: "Date and Time(From) : ${doc.data["selected_from_date"]}\n"),
                              TextSpan(text: "Date and Time(To) : ${doc.data["selected_to_date"]}\n"),
], style: TextStyle(color: Colors.black)),
class\u UserListState扩展状态{
final databaseReference=Firestore.instance;
getList()异步{
数据库参考
.收款(“预订”)
.getDocuments()
.然后((QuerySnapshot快照){
返回快照文件;
});
}
@凌驾
小部件构建(构建上下文){
回来
脚手架(
appBar:appBar(标题:Text(widget.isDelete?“删除用户”:“用户列表”),背景颜色:Colors.indigo,),
正文:ListView(
填充:所有边缘设置(12.0),
儿童:[
尺寸箱(高度:20.0),
StreamBuilder(
流:databaseReference.collection('bookings').snapshots(),
生成器:(上下文,快照){
if(snapshot.hasData){
返回列(
子项:快照.数据.文档.映射((doc){
打印(单据数据);
返回列表块(
标题:RichText(
text:TextSpan(子项:[
TextSpan(text:“Boat_id:${doc.data[“Boat_id”]}\n”),
TextSpan(text:“总计:${doc.data[“总计”]}\n”),
TextSpan(text:“乘客数量:${doc.data[“乘客数量”]}\n”),
TextSpan(text:“促销代码:${doc.data[“促销代码”]}\n”),
TextSpan(text:“日期和时间(从):${doc.data[“selected_From_Date”]}\n”),
TextSpan(text:“日期和时间(到):${doc.data[“selected_To_Date”]}\n”),
],样式:TextStyle(颜色:Colors.black)),
更改此选项:

TextSpan(text: "Date and Time(From) : ${doc.data["selected_from_date"]}\n"),
TextSpan(text: "Date and Time(To) : ${doc.data["selected_to_date"]}\n"),
为此:

TextSpan(text: "Date and Time(From) : ${doc.data["selected_from_date"].toDate()}\n"),
TextSpan(text: "Date and Time(To) : ${doc.data["selected_to_date"].toDate()}\n"),
toDate()
方法应将时间戳转换为正常日期,您可以在此处找到该方法:

更改此选项:

TextSpan(text: "Date and Time(From) : ${doc.data["selected_from_date"]}\n"),
TextSpan(text: "Date and Time(To) : ${doc.data["selected_to_date"]}\n"),
为此:

TextSpan(text: "Date and Time(From) : ${doc.data["selected_from_date"].toDate()}\n"),
TextSpan(text: "Date and Time(To) : ${doc.data["selected_to_date"].toDate()}\n"),
toDate()
方法应将时间戳转换为正常日期,您可以在此处找到该方法:


请发布firestore提供的日期格式我已在我的问题上附上了一个屏幕截图,请检查问题所在?我想检索日期和时间,因为它不是毫秒。如果您正在检索时间戳,请发布firestore数据库,您希望的时间格式是什么?!请发布日期格式ch来自firestore我的问题附上了一个屏幕截图,请检查问题是什么?我想检索日期和时间,因为它不是毫秒。如果您正在检索时间戳,请发布您的firestore数据库,您当时想要的格式是什么?!