【JS】js将 /Date(1518943415760+0800)/ 转换为2018-2-18 16:43:35格式

function formatDate(dt) {
    var year = dt.getFullYear();
    var month = dt.getMonth() + 1;
    var date = dt.getDate();
    var hour = dt.getHours();
    var minute = dt.getMinutes();
    var second = dt.getSeconds();
    return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
}
function TestIt(time) {
    //var Dtime = "\/Date(1408943415760+0800)\/";
    var t = time.slice(6, 19)
    //var d = eval('new ' + str.substr(1, str.length - 2));// 这样也可以转换成Date
    var NewDtime = new Date(parseInt(t));
    return formatDate(NewDtime);
}
console.log(TestIt("/Date(1518943415760+0800)/"));
//"2018-2-18 16:43:35"

 

posted @ 2018-04-19 16:16  willingtolove  阅读(364)  评论(0编辑  收藏  举报