previousMonth property
DateTime
get
previousMonth
Returns the previous month for the current DateTime instance.
Example usage:
final date = DateTime(2020, 2, 15);
final previousMonth = date.previousMonth;
print(previousMonth); // 2020-01-15 00:00:00.000
Implementation
DateTime get previousMonth {
var year = this.year;
var month = this.month;
if (month == 1) {
year--;
month = 12;
} else {
month--;
}
return DateTime(year, month, day, hour, minute, second, millisecond, microsecond);
}