码迷,mamicode.com
首页 > Web开发 > 详细

js获得当前系统时间

时间:2017-09-20 22:01:23      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:获得   doc   interval   return   function   eth   系统   gets   nload   

<script>

 

function get_time() {
        var date = new Date();
        var year = "", month = "", day = "", week = "", hour = "", minute = "", second = "";
        year = date.getFullYear();
        month = add_zero(date.getMonth() + 1);
        day = add_zero(date.getDate());
        hour = add_zero(date.getHours());
        minute = add_zero(date.getMinutes());
        second = add_zero(date.getSeconds());
        document.getElementById("showSysDatetime").innerHTML = " " + year + "-"
                + month + "-" + day + " " + hour + ":" + minute + ":" + second;
    }

    function add_zero(temp) {
        if (temp < 10)
            return "0" + temp;
        else
            return temp;
    }
    setInterval("get_time()", 1000);
    window.onload = get_time;

 

</script>

js获得当前系统时间

标签:获得   doc   interval   return   function   eth   系统   gets   nload   

原文地址:http://www.cnblogs.com/zhangZhangWorkHard/p/7565148.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!