Skip to content

@pmun/utils / getDaysInMonth

Function: getDaysInMonth()

ts
function getDaysInMonth(year, month): number;

获取指定月份的天数

Parameters

year

number

年份

month

number

月份(0-11),0 表示一月,11 表示十二月

Returns

number

该月的天数

Example

ts
getDaysInMonth(2023, 1) // 28(2023年2月有28天)
getDaysInMonth(2024, 1) // 29(2024年2月有29天,闰年)
getDaysInMonth(2023, 0) // 31(2023年1月有31天)