JS_13位时间戳转YYYY-YY-DD

//13位时间戳格式化
var dateFomat = function (data) {
    let date = new Date(parseInt(data));
    let y = date.getFullYear();
    let m = date.getMonth() + 1;
    m = m < 10 ? ('0' + m) : m;
    let d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    let h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    let minute = date.getMinutes();
    let second = date.getSeconds();
    minute = minute < 10 ? ('0' + minute) : minute; second = second < 10 ? ('0' + second) : second;
    // console.log( y + '-' + m + '-' + d + ' ' + ' ' + h + ':' + minute + ':' + second) 
    let dates = y + '-' + m + '-' + d + ' ' + ' ' + h + ':' + minute + ':' + second;
    return dates;
}

你可能感兴趣的:(前端)