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',  50, sortable: true },
            { field: 'S_Number', title: '学号',  100, sortable: true },
            { field: 'HW_Url', title: "作业名",  150, sortable: true },

            {
                field: 'HW_SubmitDate', title: '初次提交时间',  150,
                formatter: function (value, row, index) {
                    return changeDateFormat(value);
                }

            },

            {
                field: 'HW_UpdataDate', title: '再次提交时间',  150,
                formatter: function (value, row, index) {
                    return changeDateFormat(value);
                }

            },

            

            {
                field: 'RegistrationTime', title: "注册时间",  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: "权限",  150, sortable: true },
            {
                field: 'Enable', title: '是否启用',  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;
}
}

  

原文地址:https://www.cnblogs.com/fzqm-lwz/p/10669253.html