对jqgrid中的日期格式化
/*******************************************************************************
* 函数名称: <ATFunc>currencyFmatter</ATFunc>
* 函数功能: <ATFuncDesc>格式化jqgrid日期格式,原日期格式为Dec 25, 2018 1:14:21 PM</ATFuncDesc>
* 在colModel对象的列属性中加上 formatter:currencyFmatter,formatoptions:{format:'yyyy-MM-dd'}
* 开发人员: pdy
* 修改记录:
******************************************************************************/
function currencyFmatter(cellvalue, options, rowObject){
//console.log(options);
if(cellvalue==undefined){
return '';
}
var mydate = new Date(cellvalue);
var curyear = mydate.getFullYear();
var curmonth = mydate.getMonth();
var curday = mydate.getDate();
var hours=mydate.getHours();
var minute=mydate.getMinutes();
var second=mydate.getSeconds();
var datestr=curyear + '-' + DateToString(curmonth + 1) + '-' + DateToString(curday);
var timestr=DateToString(hours) + ':' + DateToString(minute) + ':' + DateToString(second);
if(options.colModel.formatoptions.format=='yyyy-MM-dd'){
return datestr;
}
if(options.colModel.formatoptions.format=='HH:mm:ss'||options.colModel.formatoptions.format=='hh:mm:ss'){
return timestr;
}
return datestr + ' ' + timestr;
}
function DateToString(val) {
if (val.toString().length == 1) {
return '0' + val.toString()
}
return val;
}
后来发现jqgrid自带有日期格式化工具。只需要配置为formatter:'date',formatoptions: {newformat:'Y-m-d'}即可。