Home > Web Front-end > JS Tutorial > Simple JS clock example explanation_javascript skills

Simple JS clock example explanation_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 15:20:12
Original
1820 people have browsed it

The example in this article introduces the JS clock implementation code and shares it with you for your reference. The specific content is as follows

Rendering:

Specific code:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="gb2312">
  <title>Document</title>
  <script type="text/javascript">

    function startTime () {
       var today=new Date();
    var y=today.getFullYear();
    var mon=today.getMonth()+1;
       mon=changNum(mon);
    var d=today.getDay();
       d=changNum(d);
    var h=today.getHours();
    var m=today.getMinutes();
       m=changNum(m);
    var s=today.getSeconds();
       s=changNum(s);
    document.getElementById("timeid").innerHTML=y+"年"+mon+"月"+d+"日"+h+":"+m+":"+s;
    t=setTimeout(function(){
      startTime();
    },500);
    }    

   function changNum(i){   //月、日、秒如果小于10数字前加0
       if(i<10){
          return "0"+i;
       }
       return i;
   }

  </script>
</head>
<body onload="startTime()">

<h1 id="timeid"></h1>

</body>
</html>
Copy after login

I hope this article will be helpful to everyone learning JavaScript programming.

Related labels:
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
Latest Issues
Where is js written?
From 1970-01-01 08:00:00
0
0
0
js file code not found
From 1970-01-01 08:00:00
0
0
0
js addClass not working
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template