jqgrid 时间戳格式化问题

本文介绍了一种在JSP页面中处理时间戳的方法,通过JavaScript函数实现时间选择器的功能,并利用自定义的jQuery插件格式化显示日期时间。特别针对时间戳乘以1000的情况进行了详细说明。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

jsp页面,接收到的时间参数是时间戳*1000

function bindDatePlug() {
	$(".time").addClass('Wdate');
	$(".time").on('focus', function() {
		WdatePicker({
			skin : 'whyGreen',
			dateFmt : 'yyyy-MM-dd HH:mm:ss',
			readOnly : true,
			maxDate : "%y-%M-%d %H:%m:%s"
		});
	});
}

(function($) {	
	// jqgrid插件
	$.hd_jqGrid = function(){};
	$.extend($.hd_jqGrid, {
		defaults : {
			rightHtml : "<font color='green'>√</font>",
			wrongHtml : "<font color='red'>×</font>",
			
			date_yyyy_MM_dd_HH_mm_ss : "yyyy-MM-dd HH:mm:ss",
			date_yyyy_MM_dd : "yyyy-MM-dd"
		},
		
		dateTimeFormatter : function(cellvalue, fmt) {
			return (null != cellvalue && cellvalue > 0) ? $.method.dateFormat(cellvalue, fmt) : "";
		},
		
		statusFormatter : function(cellvalue) {
			return cellvalue == 1 ? $.hd_jqGrid.defaults.rightHtml : $.hd_jqGrid.defaults.wrongHtml;
		}
	});
})(jQuery);


(function ($) {
	$.method = function(){};
	$.extend($.method, {		
		dateFormat : function( time, fmt) { // author: meizz
			if(null == fmt || typeof fmt == "undefined" || $.trim(fmt).length == 0){
				fmt = "yyyy-MM-dd HH:mm:ss";
			}
			
			if(typeof time == "number"){
				time = new Date(time);
			}
			
			var o = {
				"M+" : time.getMonth() + 1, // 月份
				"d+" : time.getDate(), // 日
				"h+" : time.getHours(), // 小时
				"H+" : time.getHours(), // 小时
				"m+" : time.getMinutes(), // 分
				"s+" : time.getSeconds(), // 秒
				"q+" : Math.floor((time.getMonth() + 3) / 3), // 季度
				"S" : time.getMilliseconds() // 毫秒
			};
			if (/(y+)/.test(fmt)) {
				fmt = fmt.replace(RegExp.$1, (time.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;
		}
	});
})(jQuery);

引用:

{
					name : 'act_time',
					index : 'act_time',
					width : 70,
					align : 'center',
					sortable : false,
					formatter : function(cellvalue, options, rowObject) {
						return $.hd_jqGrid.dateTimeFormatter(cellvalue);
					}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值