Validate number of days in a given month

前端 未结 13 2103
独厮守ぢ
独厮守ぢ 2021-01-31 18:14

Performance is of the utmost importance on this one guys... This thing needs to be lightning fast!


How would you validate the number of days in a given mont

13条回答
  •  有刺的猬
    2021-01-31 18:20

    all this logic is already built in to the javascript engine... Why recode it ? Unless you are doing this just as an exercise, you can use the javascript Date object:

    Like this:

    function daysInMonth(aDate) {
          return new Date(aDate.getYear(), aDate.getMonth()+1, 0).getDate();      
       }
    

提交回复
热议问题