nextMonth property
DateTime
get
nextMonth
Returns a DateTime instance representing the exact date of the next coming month.
Example:
DateTime currentDate = DateTime(2024, 1, 8);
DateTime nextMonthDate = currentDate.nextMonth;
print(nextMonthDate); // Output: 2023-2-08 00:00:00
The nextMonth
extension calculates and returns a new DateTime instance
with the same day and time as the original date but adjusted to the exact date of the next month.
Implementation
DateTime get nextMonth {
var year = this.year;
var month = this.month;
if (month == 12) {
year++;
month = 1;
} else {
month++;
}
return DateTime(year, month);
}