1. 程式人生 > >ajax返回json型別日期格式化

ajax返回json型別日期格式化

日期格式化涵數,格式化json型別的日期,取Date資料中time時間值即可。使用說明:在jsp中new Date,如下

eg: new Date("日期的time值").format("yyyy-MM-dd"); 

eg2:new Date(citem.regtimebegin.time).format('yyyy-MM-dd')

<script type="text/javascript">
	Date.prototype.format =function(format){
		var o = {
			"M+" : this.getMonth()+1, //month
			"d+" : this.getDate(), //day
			"h+" : this.getHours(), //hour
			"m+" : this.getMinutes(), //minute
			"s+" : this.getSeconds(), //second
			"q+" : Math.floor((this.getMonth()+3)/3), //quarter
			"S" : this.getMilliseconds() //millisecond
		}
		if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
			(this.getFullYear()+"").substr(4- RegExp.$1.length));
		for(var k in o)if(new RegExp("("+ k +")").test(format))
			format = format.replace(RegExp.$1,
				RegExp.$1.length==1? o[k] :
					("00"+ o[k]).substr((""+ o[k]).length));
		return format;
	}
</script>