如何在Flutter中获得某个日期[duplicate]

4jb9z9bj  于 2022-11-25  发布在  Flutter
关注(0)|答案(3)|浏览(136)

此问题在此处已有答案

Add/Subtract months/years to date in dart?(共10个答案)
2天前关闭。
我试图获得当前日期,然后获得它的前一天,我如何才能获得该日期,然后将其转换为字符串?

DateTime now = new DateTime.now();
fykwrbwg

fykwrbwg1#

您可以通过执行以下操作来执行此操作:

DateTime.now().subtract(Duration(days:1))

来源:https://api.flutter.dev/flutter/dart-core/DateTime-class.html

ercv8c1e

ercv8c1e2#

您可以执行以下操作:

DateTime now = DateTime.now();
DateTime nowMinus1Day = now. subtract(const Duration(days: 1));
print(nowMinus1Day.toIso8601String());
deikduxw

deikduxw3#

你可以试试这个

var now = DateTime.now();
var startDate= now.subtract(Duration(days: 1));
print(startDate);

相关问题