I stored the date in database as String and call it via model String? myDate;
, the data save as 31/12/2023 00:00:00
.
I want to dispaly in Text
widget as 31/12/2023
not 31/12/2023 00:00:00
so I tried to covnert String
to DateTime
then to String
again but the resutl is 2023-12-31 00:00:00.000
var date = '31/12/2023 00:00:00';
DateTime parseDate = intl.DateFormat("dd/MM/yyyy").parse(date);
var inputDate = DateTime.parse(parseDate.toString());
print(inputDate);
//output: 2023-12-31 00:00:00.000
How to achive my goal?
3
Answers
To achieve your goal you can do following thing
OR
you can do everything in one step
Just call these methods on the
DateTime
, its self-explanatory:Prints:
You need to play around your
String
and convert it to format that intl.DateFormat can use it.This code solves my problem: