Jquery method to determine the day of the week of a timestamp: first create a front-end sample file; then introduce jquery; finally use the "getDay()" method to return the number of the day of the week corresponding to the timestamp.
The operating environment of this tutorial: Dell G3 computer, Windows 7 system, HTML5&&CSS3&&jquery2.0.0 version.
Recommended: "css video tutorial" "javascript basic tutorial"
Jquery method to determine the day of the week when the timestamp is:
<!DOCTYPE html > <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>jquery根据日期算周次</title> </head> <body> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <script> $(function() { function ddd(types) { var text = ""; switch(types) { case 1: text = "星期一"; break; case 2: text = "星期二"; break; case 3: text = "星期三"; break; case 4: text = "星期四"; break; case 5: text = "星期五"; break; case 6: text = "星期六"; break; case 7: text = "星期日"; break; default: } return text; } var date = "2019-1-9"; var day = new Date(); var today = new Array('星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'); var week = today[day.getDay()]; //最终结果为: console.log(week); }) </script> </body> </html>
The running results are as follows:
Code introduction:
Use the getDay() method to return the number of the day of the week corresponding to the timestamp. The return value is An integer between 0 (Sunday) and 6 (Saturday). Then you can determine the day of the week based on the returned number.
Note: This method is always used in conjunction with a Date object.
For more programming-related knowledge, please visit: Programming Teaching! !
The above is the detailed content of How to determine the day of the week in jquery. For more information, please follow other related articles on the PHP Chinese website!