ajax的时间格式化

$(function () {
    
    var path = $("#path").val();

    $("#search-button").click(function(){
        var url = path + "/apiToday/search";
        var data = {
            "orderId":$("#orderId").val(),
            "productId":$("#productId").val(),
            "userId":$("#userId").val(),
            "methodName":$("#methodName").val(),
            "warnCostTime": $("select[name='warnCostTime']", "#api-method-form").val(),
            "fromNowHour": $("select[name='fromNowHour']", "#api-method-form").val()
        };

        console.log(data);
        $.ajax({
            type: "POST",
            url: url,
            data: data,
            success: function(data){
                showTimeTable(data.apiInvokeInfos);
            }
        });
        return false;
    });

    
    var format = function(time, format) {
        var t = new Date(time);
        var tf = function(i) {
            return (i < 10 ? '0': '') + i
        };
        return format.replace(/yyyy|MM|dd|HH|mm|ss/g,
        function(a) {
            switch (a) {
            case 'yyyy':
                return tf(t.getFullYear());
                break;
            case 'MM':
                return tf(t.getMonth() + 1);
                break;
            case 'mm':
                return tf(t.getMinutes());
                break;
            case 'dd':
                return tf(t.getDate());
                break;
            case 'HH':
                return tf(t.getHours());
                break;
            case 'ss':
                return tf(t.getSeconds());
                break;
            }
        });
    }

    /**
     *动态拼装展示选择时间的数据table
     *Author:wangchong
     */
    function showTimeTable(data){
        $("#timeTableTbody").empty();
        var j = 1;
        $.each(data,function(index) {   
            var i = index + 1;
            var tr = "<tr id=\"DayCountItem_" + i + "\"><td>" + j + "</td><td>" + this.methodName + "</td><td>" + this.version + "</td><td>" + this.projectName
            + "</td><td>" + this.costTime + "ms</td><td>" + format(this.invokeTime, 'yyyy-MM-dd HH:mm:ss' ) + "</td><td>" + "基本入参: orderId :" + this.orderId + ",productId :" +  this.productId + ", userId:" +  this.userId
            + "</br>" + this.debugInfo + "</td></tr>";
            $("#timeTableTbody").append(tr);
            j = j + 1;
            
        });
    }
    
});

猜你喜欢

转载自blog.csdn.net/jakeswang/article/details/77011802