js时间格式化(1)

获得时间的格式:12-25 00:00:00

function time_format(time){

        var date = new Date(time);

         M = date.getMonth()+1;

        d = date.getDate();

        h = date.getHours();

        m = date.getMinutes();

        s = date.getSeconds();

        M = M > 9 ? M  :'0'+M;

        d = d > 9 ? d : '0'+d;

        h = h > 9 ? h : '0'+h;

        m = m > 9 ? m : '0'+m;

        s = s > 9 ? s : '0'+s;

        time = M + '-' + d + ' ' +  h + '-' + m + '-' + s;

    return time;

}

你可能感兴趣的:(js时间格式化(1))