Get Weeks In Month Through Javascript

后端 未结 17 1334
盖世英雄少女心
盖世英雄少女心 2020-11-30 09:03

In Javascript, how do I get the number of weeks in a month? I can\'t seem to find code for this anywhere.

I need this to be able to know how many rows I need for a g

17条回答
  •  粉色の甜心
    2020-11-30 09:25

    function weeksinMonth(m, y){
     y= y || new Date().getFullYear();
     var d= new Date(y, m, 0);
     return Math.floor((d.getDate()- 1)/7)+ 1;     
    }
    alert(weeksinMonth(3))
    

    // the month range for this method is 1 (january)-12(december)

提交回复
热议问题