【问题标题】:Parsing date error on lower android version in flutter在颤动中解析较低的android版本上的日期错误
【发布时间】:2020-08-06 03:44:28
【问题描述】:
 var birthDate= DateFormat('yyyy/M/dd').parse(tempBirthDate);
 print(birthDate);
 String dtStringBday = DateFormat('yyyy-MM-dd').format(birthDate);
 
 //print result: 1967-08-16 00:00:00.000

您好,我正在使用此代码来解析和格式化我的日期。但我在我的 android 版本 6.0.1 SamsungJ7 上出现此错误Error: FormatException: Trying to read yyyy from at position 0,但在我的三星 A8 android 版本 7.1.1 中没有。 android版本会影响日期解析吗?还是我做错了什么?

【问题讨论】:

    标签: android flutter dart date-parsing


    【解决方案1】:

    你做错了,但你很接近 检查这个例子

    示例:

    //before we show the date we need to parse it then show it in a format Month 2 , 2020
    
         Container(
        child: Text(new DateFormat.yMMMd().format(DateTime.parse(productInfo["createdAt"]))),
                   ),
    
    // in my example this is time variable: productInfo["createdAt"]
    

    DateTime class

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-06
      相关资源
      最近更新 更多