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
Flutter 如何在列表中设置日期格式?_Flutter_Dart - Fatal编程技术网

Flutter 如何在列表中设置日期格式?

Flutter 如何在列表中设置日期格式?,flutter,dart,Flutter,Dart,是否可以设置日期列表的格式?我试图通过格式化列表来格式化它,但出现了一个错误 无法将参数类型“List”分配给参数类型“DateTime” var list = <DateTime>[]; DateTime start = DateTime(2018, 12, 30); final end = DateTime(2022, 12, 31); while (start.isBefore(end)) { list.add(start);

是否可以设置日期列表的格式?我试图通过格式化列表来格式化它,但出现了一个错误

无法将参数类型“List”分配给参数类型“DateTime”

    var list = <DateTime>[];
    DateTime start = DateTime(2018, 12, 30);
    final end = DateTime(2022, 12, 31);

    while (start.isBefore(end)) {
      list.add(start);
      start = start.add(const Duration(days: 1));
    }

    print(DateFormat("MM-dd-yyyy").format(list)); // The argument type 'List<DateTime>' can't be assigned to the parameter type 'DateTime'.
var list=[];
日期时间开始=日期时间(2018年12月30日);
最终结束=日期时间(2022、12、31);
while(start.isBefore(end)){
列表。添加(开始);
开始=开始.添加(常数持续时间(天:1));
}
打印(日期格式(“MM dd yyyy”)。格式(列表));//无法将参数类型“List”分配给参数类型“DateTime”。
当我在将日期放入列表之前格式化日期时,会出现一个错误,表示不能在字符串中使用isBefore

   var list = <DateTime>[];
    DateTime start = DateTime(2018, 12, 30);
    var date = DateFormat("MM-dd-yyyy").format(start);
    final end = DateTime(2022, 12, 31);

    while (date.isBefore(end)) { //The method 'isBefore' isn't defined for the class 'String'.
      list.add(start);
      start = start.add(const Duration(days: 1));
    }
var list=[];
日期时间开始=日期时间(2018年12月30日);
变量日期=日期格式(“MM dd yyyy”)。格式(开始);
最终结束=日期时间(2022、12、31);
而(date.isBefore(end)){//没有为类“String”定义方法“isBefore”。
列表。添加(开始);
开始=开始.添加(常数持续时间(天:1));
}

将第一个代码段更改为以下代码:

    var list = <String>[];
    DateTime start = DateTime(2018, 12, 30);
    final end = DateTime(2022, 12, 31);

    while (start.isBefore(end)) {
     var formatedData = DateFormat("MM-dd-yyyy").format(start)
      list.add(formatedData);
      start = start.add(const Duration(days: 1));
    }
var list=[];
日期时间开始=日期时间(2018年12月30日);
最终结束=日期时间(2022、12、31);
while(start.isBefore(end)){
var formatteddata=DateFormat(“MM-dd-yyyy”)。格式(开始)
列表。添加(格式化数据);
开始=开始.添加(常数持续时间(天:1));
}
由于方法返回一个
字符串
,然后将列表更改为键入
字符串
,然后在while循环中,您可以格式化
开始
日期并将其添加到列表中