首页 > 学院 > 开发设计 > 正文

js动态显示时间

2019-11-06 06:04:23
字体:
来源:转载
供稿:网友
新建文件test.html,内容如下,浏览器直接打开即可
<!DOCTYPE html><html lang="zh-CN">    <head>        <title>show time</title>        <script>            function show() {                var today = new Date();                var time = today.getFullYear() + "年"                            + format(today.getMonth() + 1) + "月"                            + format(today.getDate()) + "日 "                            + getWeek() + " "                            + format(today.getHours()) + ":"                            + format(today.getMinutes()) + ":"                            + format(today.getSeconds());                document.getElementById("time").innerHTML = time;            }            function format(value) {                if (value >= 10) return value;                return "0" + value;            }            function getWeek() {                var day = new Date().getDay();                if (day == "0") return "星期天";                if (day == "1") return "星期一";                if (day == "2") return "星期二";                if (day == "3") return "星期三";                if (day == "4") return "星期四";                if (day == "5") return "星期五";                if (day == "6") return "星期六";                return "";            }            function dynamic() {				show();                setInterval(function(){                    show();                }, 1000);            }        </script>    </head>     <body onload="dynamic();">        <span id="time"></span>    </body></html>
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表