Get week of the month

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

    Please try below function.This one is considering week start date as Monday and week end date as Sunday.

    getWeekNumber(date) {
        var monthStartDate =new Date(new Date().getFullYear(), new 
             Date().getMonth(), 1);
        monthStartDate = new Date(monthStartDate);
        var day = startdate.getDay();
        date = new Date(date);
        var date = date.getDate();
        return Math.ceil((date+ day-1)/ 7);
    }
    

提交回复
热议问题