I am trying to format my date and time.
My code
String dateStart = data[i]['notification_date'];
DateTime input = DateTime.parse(dateStart);
String datee = DateFormat('hh:mm a').format(input);
its showing error Unhandled Exception: FormatException: Invalid date format
right now its look like this 22-04-2021 05:57:58 PM
You have an issue in following line:
DateTime input = DateTime.parse(dateStart);
Thing is that default parse method does not support '22-04-2021 05:57:58 PM' format, as it is not standard. You should specify its format to parse like this:
String dateStart = '22-04-2021 05:57:58 PM';
DateFormat inputFormat = DateFormat('dd-MM-yyyy hh:mm:ss a');
DateTime input = inputFormat.parse(dateStart);
String datee = DateFormat('hh:mm a').format(input);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With