在Flutter中较低的Android版本上解析日期错误

 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,但在我的Samsung A8 Android版本7.1.1上却没有此错误。 android版本是否会影响日期解析?还是我做错了什么?

iCMS 回答:在Flutter中较低的Android版本上解析日期错误

您做错了方法,但是您非常接近 检查这个例子

示例:

//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

本文链接:https://www.f2er.com/1796629.html

大家都在问