Home > Web Front-end > JS Tutorial > How to obtain JS dynamic date and time_javascript skills

How to obtain JS dynamic date and time_javascript skills

WBOY
Release: 2016-05-16 15:37:44
Original
1100 people have browsed it

Since the code is relatively simple, the editor will not explain it anymore. You will understand it by looking at the code and post the example directly.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>实时时间</title>
  <script type="text/javascript">
    var slidint;
    function newTimer() {
      stopit();
      var today;
      today = new Date();
      var str = today.toLocaleDateString();
      str += "  " + week();
      str += "  " + today.toLocaleTimeString();
      var o = document.getElementById("lblDateTime");
      o.innerHTML = str;
      slidint = setTimeout(newTimer, 1000);
    }
      
    function stopit() {
      clearTimeout(slidint);
    }
      
    function week() {
      var d, day, x, s = " ";
      var x = new Array("星期日", "星期一", "星期二");
      var x = x.concat("星期三", "星期四", "星期五");
      var x = x.concat("星期六");
      d = new Date();
      day = d.getDay();
      return (s += x[day]);
    }
      
    window.onload = function() {
      newTimer();
    }
  </script>
</head>
<body>
  <label id="lblDateTime"></label>
</body>
</html>
Copy after login

The code implementation effect is as follows:

There are many ways to obtain dynamic time in js, and everyone needs to summarize them. I hope this article will be helpful to everyone's javascript programming design.

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