'Trying to read yy from 2022/04/17 at position 0 - in flutter

This is how I used the time and date output format, To get time on this item "getCartListHistory [itemCounter] .time"

Widget getDataTime(){
  DateTime parseData = DateFormat('yy/MM/dd HH:mm:ss').parse(getCartListHistory[itemCounter].time!);
  var inputDate = DateTime.parse(parseData.toString());
  var outPutFormat = DateFormat.yMd().add_jm();
  var outputDate = outPutFormat.format(inputDate);
  return BigText(text: outputDate);
}


Solution 1:[1]

try pass also the time when parsing it will read same pattern on DateFormat

 DateTime parseData = DateFormat('y/MM/dd HH:mm:ss').parse("2022/04/17 09:24:00");
  var inputDate = DateTime.parse(parseData.toString());
  var outPutFormat = DateFormat.yMd().add_jm();
var outputDate = outPutFormat.format(inputDate);
    log(outputDate.toString());

result :

4/17/2022 9:24 AM

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1