daysInMonth property

int get daysInMonth

Returns the number of days in the month of this date.

Example:

print(DateTime(2024, 2, 1).daysInMonth); // 29

Implementation

int get daysInMonth {
  return month == 2
      ? (isLeapYear ? 29 : 28)
      : [4, 6, 9, 11].contains(month)
          ? 30
          : 31;
}