js获取当前时间

s前端开发工具|可视化前端开发工具|app开发设计前端开发工具

html 代码

<!DOCTYPE html>
<head lang=”en”>
    <meta charset=”UTF-8″>
    <title>做前端开发要逛哪些论坛</title>
</head>
<body>
    <div id=”time”></div>
    <script type=”text/javascript”>
        function time() {
            var oDate = new Date();
            var year = oDate.getFullYear();
            var mounth = oDate.getMonth() + 1;
            var day = oDate.getDate();
            var hours = oDate.getHours();
            var minute = oDate.getMinutes();
            var seconds = oDate.getSeconds();
            var time = null;
            var week = new Array(7);
            week[0] = ‘星期天’;
            week[1] = ‘星期一’;
            week[2] = ‘星期二’;
            week[3] = ‘星期三’;
            week[4] = ‘星期四’;
            week[5] = ‘星期五’;
            week[6] = ‘星期六’;
            var weeks = week[oDate.getDay()];
            var data = document.getElementById(‘time’);
            data.innerHTML = year + ‘年’ + mounth + ‘月’ + day + ‘日’ + ‘ ‘ + weeks + ‘ ‘ + fillZero(hours) + ‘:’ + fillZero(minute) + ‘:’ + fillZero(seconds);
            function fillZero(n) {
                if (n < 10) {
                    return ‘0’ + n
                }
                else {
                    return ” + n
                }
            }
        }
        time();
        setInterval(time, 1000)
    </script>
</body>
</html>

手机网页前端开发工具|用c#开发前端框架|app开发的前端框架有哪些问题

» 本文来自:前端开发者 » 《js获取当前时间》
» 本文链接地址:https://www.rokub.com/4970.html
» 您也可以订阅本站:https://www.rokub.com
赞(0)
64K

评论 抢沙发

评论前必须登录!