Home >Web Front-end >JS Tutorial >js implements calendar to get the week number and day of the week for a specified date. Example sharing (js gets the day of the week)_Basic knowledge
Because there is interaction, I chose Js to implement it. It can be regarded as the first trial of pair programming. I will write the display part in html, and the event function triggered by the clicked button is check();
//Input value judgment part
...
//Call core function
days(theYear,theMonth,theDay);
}
The core function days are as follows:
// alert(date0.getDay());
var date1 = new Date(year ,month-1,day); //Format the date value, 0-11 represents January-December;
// alert((days date0.getDay() 6)/7);
var nthOfWeek = Math.floor((days date0.getDay() 6)/7); // Round down
// alert(nthOfWeek);
var toDay = new Array("Sunday","week "1", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
//day.getDay(); Returns a day of the week based on Date, where 0 is Sunday
alert("This date is the " days " of the year
" " It is the " nthOfWeek " week " toDay[date1.getDay()]);
}
With the assistance of teammates, he was responsible for reviewing and assisting in catching bugs, and I was responsible for Implementation and coding;
In the last step, during the testing of input values, we assisted each other very well, analyzed different input situations, covered various possible accidents, and quickly completed the improvement of the function;
The following is the code to determine whether the input value is allowed:
alert("Enter Yes Wrong, please re-enter");
return ;
}
alert("Incorrect input, please re-enter" );
return ;
}