1 <div class="showTime"></div> 2 <script> 3 var t = null; 4 t = setTimeout(time, 1000); //開始运行 5 function time() { 6 clearTimeout(t); //清除定时器 7 dt = new Date(); 8 var y = dt.getFullYear(); 9 var mt = dt.getMonth() + 1; 10 var day = dt.getDate(); 11 var h = dt.getHours(); //获取时 12 var m = dt.getMinutes(); //获取分 13 var s = dt.getSeconds(); //获取秒 14 document.querySelector(".showTime").innerHTML = 15 "当前时间:" + 16 y + 17 "年" + 18 mt + 19 "月" + 20 day + 21 "-" + 22 h + 23 "时" + 24 m + 25 "分" + 26 s + 27 "秒"; 28 t = setTimeout(time, 1000); //设定定时器,循环运行 29 } 30 </script>
标签:JS,复制,当前,time,var,dt,setTimeout,day From: https://www.cnblogs.com/zhainverer/p/17220390.html