Find all the days in a month with Date object?

后端 未结 6 1001
Happy的楠姐
Happy的楠姐 2020-11-30 01:07

is there a way to have all the days of a month or of a year? I am looking for this in order to disable some specific days in a datepicker, i would have a page in the back-of

6条回答
  •  無奈伤痛
    2020-11-30 02:09

    One liner to get all days as Date object in a month

    const getDaysInMonth = (month, year) => (new Array(31)).fill('').map((v,i)=>new Date(year,month-1,i+1)).filter(v=>v.getMonth()===month-1)
    

提交回复
热议问题