分享

实时显示当前时间,不够10的前导补0

 昵称10504424 2012-09-10
function showTime() {
        var show = document.createElement('div');
        show.setAttribute('id','d1');
        document.body.appendChild(show);
        var d1 = document.getElementById('d1');
        var currentTime = new Date;
        var hours =  currentTime.getHours();
        if(hours < 10) {
            hours = '0' + hours;    
        }
        var minutes = currentTime.getMinutes();
        if(minutes < 10) {
            minutes = '0' + minutes;    
        }
        var seconds = currentTime.getSeconds();
        if(seconds < 10) {
            seconds = '0' + seconds;    
        }
        d1.innerHTML =     currentTime.getFullYear() + '年' + (currentTime.getMonth() + 1)
 + '月' + currentTime.getDate() + '日' + ' ' + hours + '时' + minutes + '分' + seconds;    
     }
    
    window.onload = function() {
        setInterval('showTime()',1000);    
    }

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约