解决JSON序列化日期格式问题
2015-08-29 09:40
851 查看
从数据库中查询到的数据,有DateTime类型的日期数据,在返回到页面中时,如果经过了JSON序列化,则会把时间格式化成毫秒表示,就是很长的一串数字:
在页面中显示是这样的:
这种情况只需要在js中进行日期的格式化就可以了
在页面中显示是这样的:
这种情况只需要在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; } }这样就完成了日期的转换:
相关文章推荐
- jsp过滤器
- js实现栈
- js中数组迭代函数—(2)会生成新数组
- js中数组迭代函数—(1)不生成新数组
- js实现列表类
- js中数字类型数组排序
- JavaScript中字符串处理的一些函数
- js精美的幻灯片画集特效代码分享
- js实现基于正则表达式的轻量提示插件
- JS实现md5.js、md4.js、sha1.js 加密算法使用
- JavaScript中__proto__与prototype的关系
- JSOI2013编程作业
- javascript中的函数Function
- javascript的作用域
- 2015第35周五JavaScript变量
- 【ExtJs】使用Cookie、切换主题和语言
- extjs实现多国语音切换
- JSON深入浅出
- JavaScript学习笔记之Array
- JavaScript基础2——变量、作用域和内存