js时间戳转时间格式

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方法

posted @ 2018-02-02 16:34  沉迷编程的程序员  阅读(155)  评论(0编辑  收藏  举报