function getWeek(y,m,d) { let day1 = new Date(y, parseInt(m) - 1, d); let day2 = new Date(y, 0, 1); let day = Math.round((day1.valueOf() - day2.valueOf()) / 86400000); return Math.ceil((day + ((day2.getDay() + 1) - 1)) / 7) } getWeek(2019, 9, 27)
parameter:
y: Year;
m: month;
d: days.
day1 is to convert the incoming parameters to standard time, day2 is to convert the incoming year January 1 to standard time;
day is calculated incoming date and January 1 difference between the number of days;
The last return date is passed in the first few weeks of the current year.
Special note: (day2.getDay () + 1) - 1
There are two kinds of argument one week, Monday to Sunday is considered a week Sunday through Saturday is considered a week.
-1 is the natural week here (Monday to Sunday) count one week does not count -1 is Sunday to Saturday week.