原文 :http://blog.csdn.net/caoyuancsdn/article/details/52984524
Java script 接收到的时间参数是时间戳*1000
1 function bindDatePlug() { 2 $(".time").addClass('Wdate'); 3 $(".time").on('focus', function() { 4 WdatePicker({ 5 skin : 'whyGreen', 6 dateFmt : 'yyyy-MM-dd HH:mm:ss', 7 readOnly : true, 8 maxDate : "%y-%M-%d %H:%m:%s" 9 }); 10 }); 11 } 12 13 (function($) { 14 // jqgrid插件 15 $.hd_jqGrid = function(){}; 16 $.extend($.hd_jqGrid, { 17 defaults : { 18 rightHtml : "<font color='green'>√</font>", 19 wrongHtml : "<font color='red'>×</font>", 20 21 date_yyyy_MM_dd_HH_mm_ss : "yyyy-MM-dd HH:mm:ss", 22 date_yyyy_MM_dd : "yyyy-MM-dd" 23 }, 24 25 dateTimeFormatter : function(cellvalue, fmt) { 26 return (null != cellvalue && cellvalue > 0) ? $.method.dateFormat(cellvalue, fmt) : ""; 27 }, 28 29 statusFormatter : function(cellvalue) { 30 return cellvalue == 1 ? $.hd_jqGrid.defaults.rightHtml : $.hd_jqGrid.defaults.wrongHtml; 31 } 32 }); 33 })(jQuery); 34 35 36 (function ($) { 37 $.method = function(){}; 38 $.extend($.method, { 39 dateFormat : function( time, fmt) { // author: meizz 40 if(null == fmt || typeof fmt == "undefined" || $.trim(fmt).length == 0){ 41 fmt = "yyyy-MM-dd HH:mm:ss"; 42 } 43 44 if(typeof time == "number"){ 45 time = new Date(time); 46 } 47 48 var o = { 49 "M+" : time.getMonth() + 1, // 月份 50 "d+" : time.getDate(), // 日 51 "h+" : time.getHours(), // 小时 52 "H+" : time.getHours(), // 小时 53 "m+" : time.getMinutes(), // 分 54 "s+" : time.getSeconds(), // 秒 55 "q+" : Math.floor((time.getMonth() + 3) / 3), // 季度 56 "S" : time.getMilliseconds() // 毫秒 57 }; 58 if (/(y+)/.test(fmt)) { 59 fmt = fmt.replace(RegExp.$1, (time.getFullYear() + "").substr(4 - RegExp.$1.length)); 60 } 61 62 for ( var k in o) { 63 if (new RegExp("(" + k + ")").test(fmt)) { 64 fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); 65 } 66 } 67 return fmt; 68 } 69 }); 70 })(jQuery);
引用
1 { 2 name : 'act_time', 3 index : 'act_time', 4 width : 70, 7 formatter : function(cellvalue, options, rowObject) { 8 return $.hd_jqGrid.dateTimeFormatter(cellvalue); 9 } 10 }