EasyUI表格columns單元格正確顯示時間格式


下面紅色部分正是關鍵:

 這些都是同一個JS頁面的代碼:

//初始化表格
function initTable() {
    $('#test').datagrid({
        title: '學生作業列表',
        iconCls: 'icon-user',
        loadMsg: '數據加載中...',
        nowrap: true,
        autoRowHeight: true,
        striped: true,
        url: '/CorrectHomeWork/GetAllHomeWork',
        sortName: 'ID',
        sortOrder: 'asc',
        border: true,
        remoteSort: false,
        idField: 'ID',
        pageSize: 10,
        pagination: true,
        rownumbers: true,
        columns: [[
            { field: 'ck', checkbox: true },
            { field: 'ID', title: 'ID', width: 50, sortable: true },
            { field: 'S_Number', title: '學號', width: 100, sortable: true },
            { field: 'HW_Url', title: "作業名", width: 150, sortable: true },

            { field: 'HW_SubmitDate', title: '初次提交時間', width: 150, formatter: function (value, row, index) { return changeDateFormat(value); } }, { field: 'HW_UpdataDate', title: '再次提交時間', width: 150, formatter: function (value, row, index) { return changeDateFormat(value); } }, 
            

            {
                field: 'RegistrationTime', title: "注冊時間", width: 150, sortable: true,
                formatter: function (value, row, index) {
                    //return (eval(value.replace(/\/Date\((\d+)\)\//gi, "new Date($1)"))).pattern("yyyy-M-d h:m:s");
                }
            },
            { field: 'UserRoleId', title: "權限", width: 150, sortable: true },
            {
                field: 'Enable', title: '是否啟用', width: 80, formatter: function (val, rowdata, index) {
                    if (val) {
                        return '<a class="grid_Enable" href="javascript:void(0)" >' + val + '</a>';
                    } else {
                        return '<a class="grid_unEnable" href="javascript:void(0)" >' + val + '</a>';
                    }
                }
            }
        ]],
        onLoadSuccess: function () {
            $(".grid_Enable").linkbutton({ text: '啟用', plain: true, iconCls: 'icon-ok' });
            $(".grid_unEnable").linkbutton({ text: '禁止', plain: true, iconCls: 'icon-no' });
        },
        toolbar: [{
            id: 'btnadd',
            text: '添加用戶',
            iconCls: 'icon-add',
            handler: function () {
                AddUserDialog();
            }
        }, '-', {
            id: 'btnedit',
            text: '修改用戶',
            iconCls: 'icon-edit',
            handler: function () {
                UpdateUserDialog();
            }
        }, '-', {
            id: 'btncut',
            text: '刪除用戶',
            iconCls: 'icon-cut',
            handler: function () {
                DeleteUser();
            }
        }, '-', {
            id: 'btnrefresh',
            text: '刷新',
            iconCls: 'icon-reload',
            handler: function () {
                initTable();
            }
        }]
    });
}

 

//轉換日期格式 
function changeDateFormat(cellval) {
if (cellval != null) {
var date = new Date(parseInt(cellval.replace("/Date(", "").replace(")/", ""), 10));
var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
var currentHours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();

var currentMinutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
var currentSeconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();

return date.getFullYear() + "-" + month + "-" + currentDate + " "+" " + currentHours + ":" + currentMinutes + ":" + currentSeconds;
}
}

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM