- Date.prototype.Format = function(fmt) { //author: meizz
- var o = {
- "M+": this.getMonth() + 1,
- //月份
- "d+": this.getDate(),
- //日
- "h+": this.getHours(),
- //小时
- "m+": this.getMinutes(),
- //分
- "s+": this.getSeconds(),
- //秒
- "q+": Math.floor((this.getMonth() + 3) / 3),
- //季度
- "S": this.getMilliseconds() //毫秒
- };
- if (/(y+)/.test(fmt)) {
- fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
- }
- for (var k in o) {
- if (new RegExp("(" + k + ")").test(fmt)) {
- fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
- }
- }
- return fmt;
- }
然后直接在 columns.render 里面调用这个方法就好(代码里面的注释是告诉大家问题归类的思路,因为很多人不知道自己的问题出在那里)
- render: function(data, type, row, meta) {
- //先讲 时间格式化
- //这类问题主要给大家讲逻辑,因为都是类似的问题,类似的解决方案
- //最基础的解决方案: 一、直接在数据源就格式化为常见的格式(sql或者后台代码格式化);二、在dt里面格式化;
- //在js格式化时间的三种方式,我这里示范一种
- //具体方法的链接:http://www.cnblogs.com/zhangpengshou/archive/2012/07/19/2599053.html
- return (new Date(data)).Format("yyyy-MM-dd hh:mm:ss"); //date的格式 Thu Apr 26 2016 00:00:00 GMT+0800
- }