I tried calling this code:
var test = int.parse(DateFormat('yyyy').format(formattedTemporaryDate));
but I get the error:
type 'String' is not a subtype of type 'DateTime'
my formattedTemporaryDate is '2022-01-08'
I think I need to transform the formattedTemporaryDate to an int, but I don't know how. And I even don't know if this really is the problem... Do you need more information to fix my problem?
CodePudding user response:
Just use DateTime.parse('2022-01-08') instead of just String.
Something like var formattedTemporaryDate = DateTime.parse('2022-01-08');
CodePudding user response:
What would you like var test to be at the end? A datetime? An int representation of the date?
You can convert your string to a DateTime object by calling DateTime.parse()
var formattedTemporaryDate = '2022-01-08';
DateTime dt = DateTime.parse(formattedTemporaryDate);
print(dt); // 2022-01-08 00:00:00.000
If you then want to convert it to an Int (maybe because you're doing UNIX Timestamp stuff?) You could try reverse-engineering some of the code people added here going the other direction.
