Get week of the month

前端 未结 14 1792
野趣味
野趣味 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 think this works. It returns the week of the month, starting at 0:

    var d = new Date();
    var date = d.getDate();
    var day = d.getDay();
    
    var weekOfMonth = Math.ceil((date - 1 - day) / 7);
    

提交回复
热议问题