• 当前时间


    代码

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
    </head>
    
    <body>
        <div id="box"></div>
        <script>
            var box = document.getElementById('box');
            var weeks = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
    
    
            setInterval(auto, 1000);
            function auto() {
                var date = new Date();
                var year = date.getFullYear();
                var month = date.getMonth() + 1;
                var day = date.getDate();
                var weekDay = date.getDay();
                var hour = date.getHours();
                var minute = date.getMinutes();
                var second = date.getSeconds();
    
                box.innerHTML = year + '' + month + '' + day + '日,' + weeks[weekDay] + '&nbsp;' + addZero(hour) + ':' + addZero(minute) + ':' + addZero(second);
            }
            auto();
    
            // 加0封装
            function addZero(time) {
                // if (time >= 10) {
                //    return time = time;
                // } else {
                //    return  time = '0' + time
                // }
                return time = time >=10? time:'0'+time
            }
        </script>
    </body>
    
    </html>

    效果

  • 相关阅读:
    python中类中的@property
    Python列表的三种遍历(序号和值)的方法
    Numpy一文全了解
    python中list操作方法
    Material Design
    android动画xml
    java配置opencv-在eclipse中
    android 重装sdk或者系统的时模拟器出现can open ****
    hdu acm 1005
    hdu acm 1007
  • 原文地址:https://www.cnblogs.com/shihaiying/p/13230143.html
Copyright © 2020-2023  润新知