13,347
社区成员
发帖
与我相关
我的任务
分享
function formatDate(obj,style) {
if (!obj) {
return '';
}
var date = new Date(parseInt(obj.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 hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
var minu = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
var sec = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
if (style == 0) {
return date.getFullYear() + "-" + month + "-" + currentDate + " " + hour + ":" + minu + ":" + sec;
}
if (style == 1) {
return date.getFullYear() + "-" + month + "-" + currentDate;
}
if (!style) {
return date.getFullYear() + "-" + month + "-" + currentDate + " " + hour + ":" + minu + ":" + sec;
}
}
调用
field: 'upload_date', title: "上传时间", width: 100, sortable: true, align: "center",
formatter: function (value, row, index) {
return formatDate(value, 1);
你点编辑回填绑定数据的时候也调用下这个formatDate()函数试试
$.extend($.fn.datebox.defaults,{
formatter:function(date){
var y = date.getFullYear();
var m = date.getMonth()+1;
var d = date.getDate();
return (d<10?('0'+d):d)+'/'+(m<10?('0'+m):m)+'/'+y;
},
parser:function(s){
if (!s) return new Date();
var ss = s.split('/');
var d = parseInt(ss[0],10);
var m = parseInt(ss[1],10);
var y = parseInt(ss[2],10);
if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
return new Date(y,m-1,d);
} else {
return new Date();
}
}