js将json数组对象属性的date显示出来

java里面时间类型转换成json数据就成这样了
"crtTime":{"date":30,"day":3,"hours":15,"minutes":14,"month":3,"nanos":0,"seconds":38,  
"time":1209539678000,"timezoneOffset":-480,"year":108} 


数据库里的格式是yyyy-MM-dd hh:mm:ss
页面上若还是想以这种格式展示的话,需要做下转换:
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;
}

var time = new Date(data.crtTm.time).format("yyyy-MM-dd hh:mm:ss");


这样就以正常格式显示,这是js里的处理方式,在java后台能转换,可在获取
long time = JSON.parseObject(str).getLong("time");
的值后再做相应转换,也可使用JsonValueProcessor将date转换成希望的类型,相关文章链接:
http://blessht.iteye.com/blog/2018901

猜你喜欢

转载自zisetoufa.iteye.com/blog/2307737