Get week of the month

前端 未结 14 1783
野趣味
野趣味 2020-11-30 08:55

How can i get the week number of month using javascript / jquery?

For ex.:

First Week: 5th July, 2010. / Week Number = First monday

14条回答
  •  野性不改
    2020-11-30 09:19

    I was just able to figure out a easier code for calculate the number of weeks for a given month of an year ..

    y == year for example { 2012 } m == is a value from { 0 - 11 }

    function weeks_Of_Month( y, m ) {
        var first = new Date(y, m,1).getDay();      
        var last = 32 - new Date(y, m, 32).getDate(); 
    
        // logic to calculate number of weeks for the current month
        return Math.ceil( (first + last)/7 );   
    }
    

提交回复
热议问题