Home  >  Article  >  Web Front-end  >  How to determine the day of the week in jquery

How to determine the day of the week in jquery

藏色散人
藏色散人Original
2020-12-30 09:54:462372browse

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.

How to determine the day of the week in jquery

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(&#39;星期日&#39;, &#39;星期一&#39;, &#39;星期二&#39;, &#39;星期三&#39;, &#39;星期四&#39;, &#39;星期五&#39;, &#39;星期六&#39;);
  var week = today[day.getDay()];
  //最终结果为:
  console.log(week);
})
</script>
</body>
</html>

The running results are as follows:

How to determine the day of the week in jquery

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!

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