解决JSON序列化日期格式问题

        从数据库中查询到的数据,有DateTime类型的日期数据,在返回到页面中时,如果经过了JSON序列化,则会把时间格式化成毫秒表示,就是很长的一串数字:

在页面中显示是这样的:


        这种情况只需要在js中进行日期的格式化就可以了

$('#searchInfo').datagrid({
      columns: [[
                 { field: 'ck', checkbox: false },
                 { title: '主键', field: 'b_basicInformationNumber', hidden: true },
                 { title: '档案编号', field: 'b_ID', sortable: true, hidden: true, },
                 { title: '姓名', field: 'b_name', sortable: true },
                 { title: '性别', field: 'b_sex', sortable: true, },
                 { title: '身份证号', field: 'b_idNumber', sortable: true, },
                 { title: '接收方式', field: 'b_receivemode', sortable: true },
                 { title: '本人身份', field: 'b_myidentity', sortable: true },
                 { title: '学历', field: 'pmt_educationBackground', sortable: true },
                 { title: '原工作单位', field: 'b_oldworkplace', sortable: true },
                 { title: '缴费截止日期', field: 'b_stoptime', sortable: true, <span style="color:#FF0000;">formatter: 
                                    function (value, row, index) { return changeDateFormat(value) }</span> },
                 { title: '档案在否', field: 'b_isrecord', sortable: true },
                 { title: '操作', field:'oc',formatter: function (value, row, index) { return OperateColumn(value, row, index) } }
                
             ]]

})
通过对缴费截止日期列的格式化,通过方法changeDateFormat()来完成:

 //转换日期格式     
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();             
         return date.getFullYear() + "-" + month + "-" + currentDate; 
         }
 }
这样就完成了日期的转换:


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 9
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值