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

How to determine the day of the week in jquery

藏色散人
Release: 2023-01-04 09:38:19
Original
2470 people have browsed it

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template