简体   繁体   中英

Custom week number of year for school

我试图通过修改iso周数来显示学期学期周数。

you cannot compare a number to multiple values like that

if (weekNo >= 5 && <= 18)

is illegal syntax. instead you make two comparisons joined with a "logical and" operator: &&

if (weekNo >= 5 && weekNo <= 18)

This says: "if weekNo is greater than or equal to 5" AND "if weekNo is less than or equal to 18"

Each side of the && operator is considered a separate statement for evaluation. It is expecting an identifier after the && .

Rewrite it like this for each of your if statements:

weekNo >= 5 && weekNo <= 18 

You are missing some formatting as others have pointed out and there is a rogue comma bewfore the return statement. I have formatted your block for you.

 function getWeekNumber(d) { // Copy date so don't modify original d = new Date(+d); d.setHours(0,0,0,0); // Set to nearest Thursday: current date + 4 - current day number // Make Sunday's day number 7 d.setDate(d.getDate() + 4 - (d.getDay()||7)); // Get first day of year var yearStart = new Date(d.getFullYear(),0,1); // Calculate full weeks to nearest Thursday var weekNo = Math.ceil((( (d - yearStart) / 86400000) + 1)/7); // Return array of year and week number //modify week number to display 1-12 semester 2 if (weekNo >= 5 && weekNo <= 18 ) { var schoolWeekNo = weekNo - 4; var semester = 2; } //modify week number to display 1-12 semester 1 else if (weekNo >= 39 && weekNo<= 50) { var schoolWeekNo = weekNo - 38; var semester = 1; } //do not display week number for none semester dates else { schoolWeekNo = null; semester = null; }; return [semester,schoolWeekNo]; }; alert(getWeekNumber(Date.now())); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM