對jqgrid中的日期格式化

對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);
	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;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章