Get the days in a Week in Javascript, Week starts on Sunday

前端 未结 4 1015
长情又很酷
长情又很酷 2021-01-19 18:29

Here\'s the given input from the user:

Year = 2011, Month = 3 (March), Week = 2

I want to get the days in week 2 of March 2011 in JavaScript.

e.g. Su

4条回答
  •  太阳男子
    2021-01-19 19:06

    I normally use Datejs for date manipulations in js. I'd do it like this:

    var firstDayOfWeek = new Date(year,month-1,1).moveToDayOfWeek(0,-1).addWeeks(week-1);
    var lastDayOfWeek = firstDayOfWeek.addDays(6);
    

提交回复
热议问题