您现在的位置是:首页 > 其他

李清波 2017-09-08 其他 1874 复制当前网址

时间不足10位补0方案


自动补零

(function() {

    //创建补0函数
    function p(s) {
        return s < 10 ? '0' + s: s;
    }
 
    //创建、格式化时间函数
    var younger_time = function(time) {
        var time = new Date(time);
        var year = time.getFullYear();
        var month = time.getMonth() + 1;
        var day = time.getDate();
 
        //格式化时间
        var str = year + '-' + p(month) + '-' + p(day);
 
        //写入时间格式为 xxxx-xx-xx
        document.getElementById("div_ID").innerHTML = str;
    }
 
    //服务器时间(毫秒为单位)
    younger_time(ServerTime * 1000);
})()


文章来源:http://liqingbo.com/blog-1466.html

评论