Home  >  Article  >  Web Front-end  >  How to calculate the day of the week with jquery

How to calculate the day of the week with jquery

青灯夜游
青灯夜游Original
2022-06-09 16:06:512379browse

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]".

How to calculate the day of the week with jquery

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.

How to calculate the day of the week with jquery

2. Use new Date() to get the current time

How to calculate the day of the week with jquery

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.

How to calculate the day of the week with jquery

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 .

How to calculate the day of the week with jquery

Look at the results:

How to calculate the day of the week with jquery

How to calculate the day of the week with jquery

##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 tutorial

, web front-end video]

The 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn