函数可以把时间戳转成yyyy-mm-dd hh:mm:ss格式的时间

function dateFormat(timestamp) {
    var time = new Date(parseInt(timestamp));
    var y = time.getFullYear();
    var m = time.getMonth() + 1;
    m = m > 9 ? m : '0' + m;
    var d = time.getDate();
    d = d > 9 ? d : '0' + d;
    var h = time.getHours();
    h = h > 9 ? h : '0' + h;
    var mm = time.getMinutes();
    mm = mm > 9 ? mm : '0' + mm;
    var s = time.getSeconds();
    s = s > 9 ? s : '0' + s;
    return y + '-' + m + '-' + d + ' ' + h + ':' + mm + ':' + s;
}

 

posted @ 2020-04-06 09:23  枚齐元子  阅读(364)  评论(0编辑  收藏  举报