Get week of the month

前端 未结 14 1764
野趣味
野趣味 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:24

    This is nothing natively supported.

    You could roll your own function for this, working from the first day of the month

    var currentDate = new Date();
    var firstDayOfMonth = new Date( currentDate.getFullYear(), currentDate.getMonth(), 1 );
    

    And then getting the weekday of that date:

    var firstWeekday = firstDayOfMonth.getDay();
    

    ... which will give you a zero-based index, from 0-6, where 0 is Sunday.

提交回复
热议问题