js时间戳转时间格式

时间:2021-07-24 02:34:22
function data_string(str) {
    var d = eval('new ' + str.substr(1, str.length - 2));
    console.log(d);
    return formatDate(d);
}
function formatDate(now) {
    var year = now.getFullYear();
    var month = now.getMonth() + 1;
    var date = now.getDate();
    var hour = now.getHours();
    var minute = now.getMinutes();
    var second = now.getSeconds();
    return year + "-" + month + "-" + date + "   " + hour + ":" + minute + ":" + second;
}

调用data_string方法