JS动态日期时间的获取方法

由于代码比较简单,小编就不再讲解,看代码就明白了,直接把实例帖出来。

<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></label> </body> </html>

代码实现效果如下:

JS动态日期时间的获取方法

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wggwpd.html