Home > Article > Web Front-end > How to calculate the day of the week with jquery
Method to calculate the day of the week: 1. Define the "array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")" array; 2. Use the "new Date()" statement to obtain the current date; 3. Use the getDay() function to format the obtained date and convert it into a number representing the current week. The syntax is "current date object.getDay()"; 4. Use the obtained number as a subscript and retrieve the corresponding week value in the array. The syntax is "array name [number]".
The operating environment of this tutorial: windows7 system, jquery3.6.0 version, Dell G3 computer.
In jquery, you can use new Date() to get the current date, and then use the getDay() method to get the day of the week.
Implementation method
1. Create an array and store the Chinese name of the week in the array.
2. Use new Date() to get the current time
3. Use the getDay() method to get the day of the week .
Use today's time object and use the getDay() method to get today's week number. The number 0 is Sunday and the numbers 1 to 6 are Monday to Saturday.
4. Use the obtained number as a subscript to get the corresponding week value in the array
Through the week number in the previous step, get the week value from the array week Get the Chinese name of the week from .
Look at the results:
##Instructions:## The #getDay() method returns a number representing the day of the week.
dateObject.getDay()
dateObject refers to a day of the week, using local time. The return value is an integer between 0 (Sunday) and 6 (Saturday).
So if you need to accurately give the current day of the week, you need to define an Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", " Saturday") array.
Then use the number returned by getDay() as a subscript and take out the corresponding week value in the array.
[Recommended learning:
jQuery video tutorialThe above is the detailed content of How to calculate the day of the week with jquery. For more information, please follow other related articles on the PHP Chinese website!