This function is used to calculate the week number of the current month.
The Code is as follows:
Var getMonthWeek = function (a, B, c ){
/*
A = d = current date
B = 6-w = there are still several days to finish the current week (not today)
Divide the sum of a + B by 7, which is the week of the current month.
*/
Var date = new Date (a, parseInt (B)-1, c), w = date. getDay (), d = date. getDate ();
Return Math. ceil (
(D + 6-w)/7
);
};
Var getYearWeek = function (a, B, c ){
/*
Date1 is the current date
Date2 is the first day of the year.
D indicates the number of days of the current year.
Use d + to divide the week gap on the first day of the current year by 7, which is the week of the current year.
*/
Var date1 = new Date (a, parseInt (B)-1, c), date2 = new Date (a, 0, 1 ),
D = Math. round (date1.valueOf ()-date2.valueOf ()/86400000 );
Return Math. ceil (
(D + (date2.getDay () + 1)-1)/7
);
};
Document. write (
"Today is the day of the month", getMonthWeek (2007, 03, 19), "Week
"
, "Today is the day of the year", getYearWeek (2007, 03, 19), "Week"
);