i have DateTime.now().toIso8601String() = 2022-08-09T03:01:32.223255
how can i find if 3 days have passed since the date ?
CodePudding user response:
You can parse string to DateTime
object:
final dateTime = DateTime.now();
final stringDateTime = dateTime.toIso8601String();
final parsedDateTime = DateTime.parse(stringDateTime);
In this case, dateTime and parseDateTime are the same.
Then to find out the time difference use difference
DateTime instance method, which returns Duration instance. Example from dart documentation:
final berlinWallFell = DateTime.utc(1989, DateTime.november, 9);
final dDay = DateTime.utc(1944, DateTime.june, 6);
final difference = berlinWallFell.difference(dDay);
print(difference.inDays); // 16592
CodePudding user response:
Use the difference function on DateTime object:
DateTime now = DateTime.now();
DateTime addedThreeDays = DateTime.now().add(Duration(days: 3));
print(3 >= now.difference(addedThreeDays).abs().inDays);