| title | getDaysInMonth() |
|---|
Returns the number of days in a given month of a specific year. Correctly handles leap years when calculating February.
getDaysInMonth(date)
getDaysInMonth(year, month)| Parameter | Type | Required | Description |
|---|---|---|---|
date |
Date |
Yes (overload 1) | The date object whose month to examine |
year |
number |
Yes (overload 2) | The Gregorian year (1–9999) |
month |
number |
Yes (overload 2) | The month (1–12) |
number - The number of days in the specified month
import { getDaysInMonth } from 'date-and-time';
getDaysInMonth(new Date(2024, 1, 1)); // => 29 (Feb 2024, leap year)
getDaysInMonth(new Date(2023, 1, 1)); // => 28 (Feb 2023, not a leap year)
getDaysInMonth(new Date(2025, 0, 1)); // => 31 (January 2025)import { getDaysInMonth } from 'date-and-time';
getDaysInMonth(2024, 2); // => 29 (Feb 2024, leap year)
getDaysInMonth(2023, 2); // => 28 (Feb 2023, not a leap year)
getDaysInMonth(2025, 4); // => 30 (April 2025)
getDaysInMonth(2025, 12); // => 31 (December 2025)isLeapYear()- Check if a year is a leap yearaddMonths()- Add months to a date