Reputation: 185
I would like to display the previous date How do I do that?
i used this methode for display the date of today, i also want to display the previous date.
static final DateTime now = DateTime.now();
static final DateFormat formatter = DateFormat('dd-MM-yyyy');
final String formatted = formatter.format(now);
Upvotes: 3
Views: 1457
Reputation: 79
You can add or subtract values
DateTime today = DateTime.now();
DateTime fiftyDaysAgo = today.subtract(const Duration(days: 50));
https://api.flutter.dev/flutter/dart-core/DateTime-class.html
Upvotes: 1
Reputation: 1880
final now = DateTime.now();
final today = DateTime(now.year, now.month, now.day);
final yesterday = DateTime(now.year, now.month, now.day - 1);
final tomorrow = DateTime(now.year, now.month, now.day + 1);
Upvotes: 3