渡课学习第22天

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <style type="text/css"></style>
</head>
<body>
    <div id="content"></div>
    <script type="text/javascript">
        var formatNum = function(num) {
            if (num < 10) return "0" + num;
        return num;
        }

        var dateFormat = function() {
            var result = "xxxx";
            var now = new Date();
            var year = formatNum(now.getFullYear());
            var month = formatNum(now.getMonth() + 1);
            var date = formatNum(now.getDate());
            var hour = formatNum(now.getHours());
            var minute = formatNum(now.getMinutes());
            var second = formatNum(now.getSeconds());

            result = ""+year+"年"+month+"月"+date+"日"+hour+":"+minute+":"+second+" ";
            document.getElementById("content").innerHTML = result;

        }
        dateFormat();
        setInterval(dateFormat,1000);

    </script>

</body>
</html>

猜你喜欢

转载自blog.csdn.net/linlinAIR/article/details/81394890