Solve the problem of time with character T returned by JSON (front-end solution)

1. When the type of updatetime in the database is datatime instead of varchar, using ajax operation, a string with T appears when it is converted to json, and it is displayed one more day than the original time in the 360 ​​browser. (eg: October 30 becomes October 31)
function showArticleList(id)
{
    var myUrl = "../api/Articles";
    $.ajax({
        type: 'GET',
        url: myUrl,
        data: {
            page: iIndex, rows: 13,  sort: "UpdateTime",  order: "desc", ChannelID: id,AuditState: 3
        },
         dataType:"json",
        success: function (data)
        {
            var myHtml = "";
            if (data.total == 0) {
                pageTool.setTotal(data.total);
                $(".Page").hide();
                myHtml = "

No relevant records

";
                $("#article-list").html(myHtml);
            }
            else {
                $(".Page").show();
                pageTool.setTotal(Math.ceil(data.total /13));
            }
            $("#rows").html(data.total);
            //$("#rows").html(data.rows.length);
            var myHtml = "";
            for (var i = 0; i < data.rows.length; i++)
            {
                myHtml += "
";
                myHtml += "
  • [" + timeFormat(data.rows[i].UpdateTime) + "]
  • ";
                myHtml += "
  • ";
                myHtml += " " + (i + 1) + "." + data.rows[i].Title + " ";
            }
            $("#article-list").html(myHtml);
        },
        error: function ()
        {
            ;
        }

    })
}


//日期格式转化
function timeFormat(iTime) {
     var iTime = new Date(iTime + "+08:00");//格式化时间,参数:JSON返回的时间(带T格式)
    var month = iTime.getMonth() + 1 < 10 ? "0" + (iTime.getMonth() + 1) : iTime.getMonth() + 1;
    var day = iTime.getDate() < 10 ? "0" + iTime.getDate() : iTime.getDate();
    var milliseconds = iTime.getMilliseconds();
    return iTime.getFullYear() + "-" + month + "-" + day;
    ;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324782534&siteId=291194637