Home > database >  Flutter/Dart : Parsing 'yyyy-MM-dd HH:MM:SS' producing wrong output?
Flutter/Dart : Parsing 'yyyy-MM-dd HH:MM:SS' producing wrong output?

Time:02-10

I am parsing a date in format yyyy-MM-dd HH:MM:SS using DateFormat

But I am getting some other date in parsed output

final dt = '2022-02-07 05:00:11';
final datm =  DateFormat('yyyy-MM-dd HH:MM:SS').parse(dt);

print ("DATE_CALC ${datm.day} - ${datm.month} - ${datm.year} ${datm.hour} : ${datm.minute} : ${datm.second}   "); 

Actual Output:

DATE_CALC 7 - 2 - 2021 5 : 0 : 0 

Expected :

DATE_CALC 07 - 12 - 2022 05 : 00 : 11 

Why I am getting some wrong date ? Am I doing anything wrong ?

CodePudding user response:

MM is not month and minutes.... mm or MM :-)

wrong 'yyyy-MM-dd HH:MM:SS'
correct 'yyyy-MM-dd HH:mm:ss'

CodePudding user response:

final dt = '2022-02-07 05:00:11';
final datm =  DateFormat("yyyy-MM-dd HH:mm:ss").parse(dt);
  print ("DATE_CALC ${datm.day} - ${datm.month} - ${datm.year} ${datm.hour} : ${datm.minute} : ${datm.second}   ");

Try this Hour minute and seconds can be parsed like this HH:mm:ss not like HH:MM:SS

CodePudding user response:

Your formate is wrong

yyyy-MM-dd HH:MM:SS replace to 'yyyy-MM-dd HH:mm:ss'

CodePudding user response:

it should be final datm = DateFormat('yyyy-MM-dd HH:mm:ss').parse(dt);

  • Related