easyui datagrid 中序列化后的日期格式化

1、在easyui datagrid 中序列化后的日期显示为:/Date(1433377800000)/

2、格式化后的显示为: 2015-06-04 08:30:00

3、使用代码如下:

3.1、

    <script type="text/javascript">
        $(function () {
            $("#tdList").datagrid({
                url: "/Admin/Dictionary/Index",                
                title: "数据字典列表",
                loadMsg: '正在加载信息...',
                width: "100%",                
                idField: "Id",                
                fitColumns: true,
                pagination: true,
                pageSize: 10,
                pageList: [10, 20, 35, 50],                
                singleSelect: true,
                rownumbers: true,
                columns: [[
						{ field: 'ck', checkbox: true, align: 'left', width: 50 },
                        { field: 'Name', title: '名称', width: 120 },					
						{ field: 'DisOrder', title: '字典类别', width: 80 },					
                        { field: 'Description', title: '备注', width: 120 },
                        {
                            field: 'UpdateTime', title: '最后更新时间', width: 80, align: 'right',                            
                            formatter: function (value, row, index) {
                                var datetime = Common.formatterDateTime(value);

                                return datetime;                              
                            }
                        }

                ]],
                toolbar: [{
                    id: 'add',
                    text: '添加',
                    iconCls: 'icon-add',
                    handler: add
                }],
                onLoadSuccess: function (data) {
                    if (!data.rows) {
                        var body = $(this).data().datagrid.dc.body2;
                        body.find('table tbody').append('<tr><td width="' + body.width() + '" style="height: 25px; text-align: center;">没有数据</td></tr>');
                    }
                }
            });
        });
               

        function add(){
            $("#add").dialog({
                title: "添加数据字典类别",
                collapsible: true,
                minimizable: true,
                maximizable: true,
                resizable: true,
                width: 400,
                height: 260,
                buttons: [{
                    text: "保存",
                    iconCls: "icon-add",
                    handler: function () {
                        $("#add form").submit();
                    }
                }, {
                    text: "取消",
                    iconCls: "icon-cancel",
                    handler: function () {
                        $("#add").dialog("close");
                    }
                }]
            });
        };

    </script>

3.2、引用Common.js文件,Common.js内容如下:

var Common = {
    /**
     * 格式化日期(不含时间)
     */
    formatterDate: function (date) {
        if (date == undefined) {
            return "";
        }
        /*json格式时间转js时间格式*/
        date = date.substr(1, date.length - 2);
        var obj = eval('(' + "{Date: new " + date + "}" + ')');
        var date = obj["Date"];
        if (date.getFullYear() < 1900) {
            return "";
        }

        var datetime = date.getFullYear()
                + "-"// "年"
                + ((date.getMonth() + 1) > 10 ? (date.getMonth() + 1) : "0"
                        + (date.getMonth() + 1))
                + "-"// "月"
                + (date.getDate() < 10 ? "0" + date.getDate() : date
                        .getDate());
        return datetime;
    },
    /**
     * 格式化日期(含时间"00:00:00")
     */
    formatterDate2: function (date) {
        if (date == undefined) {
            return "";
        }
        /*json格式时间转js时间格式*/
        date = date.substr(1, date.length - 2);
        var obj = eval('(' + "{Date: new " + date + "}" + ')');
        var date = obj["Date"];
        if (date.getFullYear() < 1900) {
            return "";
        }

        /*把日期格式化*/
        var datetime = date.getFullYear()
                + "-"// "年"
                + ((date.getMonth() + 1) > 10 ? (date.getMonth() + 1) : "0"
                        + (date.getMonth() + 1))
                + "-"// "月"
                + (date.getDate() < 10 ? "0" + date.getDate() : date
                        .getDate()) + " " + "00:00:00";
        return datetime;
    },
    /**
     * 格式化去日期(含时间)
     */
    formatterDateTime: function (date) {
        if (date == undefined) {
            return "";
        }
        /*json格式时间转js时间格式*/
        date = date.substr(1, date.length - 2);
        var obj = eval('(' + "{Date: new " + date + "}" + ')');
        var date = obj["Date"];
        if (date.getFullYear() < 1900) {
            return "";
        }

        var datetime = date.getFullYear()
                + "-"// "年"
                + ((date.getMonth() + 1) > 10 ? (date.getMonth() + 1) : "0"
                        + (date.getMonth() + 1))
                + "-"// "月"
                + (date.getDate() < 10 ? "0" + date.getDate() : date
                        .getDate())
                + " "
                + (date.getHours() < 10 ? "0" + date.getHours() : date
                        .getHours())
                + ":"
                + (date.getMinutes() < 10 ? "0" + date.getMinutes() : date
                        .getMinutes())
                + ":"
                + (date.getSeconds() < 10 ? "0" + date.getSeconds() : date
                        .getSeconds());
        return datetime;
    }
};

  

 

posted @ 2015-06-08 15:06  小个子猫  阅读(6310)  评论(2编辑  收藏  举报