• js获取当前时间&js 页面时钟


    js获取当前时间

    //获取当前时间,格式YYYY-MM-DD
        function getNowFormatDate() {
            var date = new Date();
            var seperator1 = "-";
            var year = date.getFullYear();
            var month = date.getMonth() + 1;
            var strDate = date.getDate();
            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }
            if (strDate >= 0 && strDate <= 9) {
                strDate = "0" + strDate;
            }
            var currentdate = year + seperator1 + month + seperator1 + strDate;
            return currentdate;
        }

    js页面添加时钟

    <script type="text/javascript">
    function realSysTime(clock){
        var now = new Date();
        var year = now.getFullYear();
        var month = now.getMonth();
        var date = now.getDate();
        var day = now.getDay();
        var hour = now.getHours();
        var minu = now.getMinutes();
        var sec = now.getSeconds();
        month = month+1;
        var arr_week = new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
        var week = arr_week[day];
        var time = year+"年"+month+"月"+date+"日"+" "+week+" "+hour+":"+minu+":"+sec;
        clock.innerHTML=time;
    }
    window.onload=function(){
        window.setInterval("realSysTime(clock)", 1000);
    }
    </script>

    <div id="clock"></div>
  • 相关阅读:
    Java 定时任务
    Swing中常用的方法
    瀑布流ajax分页
    权限管理
    图片自动加水印
    jsp自动生成静态页(提供思路)
    分页查询语句
    使用phpmailer发送邮件(以QQ邮箱为例)
    在浏览器的标签页显示网站标志图标(或指定图标)的方法
    随机生成验证码
  • 原文地址:https://www.cnblogs.com/nshuai/p/5845401.html
Copyright © 2020-2023  润新知