返回json格式时间,解析时间

时间:2021-05-19 16:05:04

传入:Json格式的时间

JS如下:

yyyy-M(MM)-d(dd) H(HH):m(mm):s(ss)

function timeStamp2String(time)
{
var data=time;
var datetime=new Date(parseInt(data.replace("/Date(","").replace(")/",""),));
var year=datetime.getFullYear();
var month=datetime.getMonth()+;
var date=datetime.getDate();
var hour=datetime.getHours();
var minute=datetime.getMinutes();
var second=datetime.getSeconds();
return year+"-"+month+"-"+date+" "+hour+":"+minute+":"+second;
}

  yyyy-MM-dd HH:mm:ss

function timeStamp2String(time)
{
    var data = time;
        var datetime = new Date(parseInt(data.replace("/Date(", "").replace(")/", ""), 10));
        var year = datetime.getFullYear();
        var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
        var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
        var hour = datetime.getHours() < 10 ? "0" + datetime.getHours() : datetime.getHours();
        var minute = datetime.getMinutes() < 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
        var second = datetime.getSeconds() < 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
        return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
}

运用时,在js中调用