1 [javascript] view plaincopyprint? 2 function timeStamp2String(time){ 3 var datetime = new Date(); 4 datetime.setTime(time); 5 var year = datetime.getFullYear(); 6 var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1; 7 var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate(); 8 var hour = datetime.getHours()< 10 ? "0" + datetime.getHours() : datetime.getHours(); 9 var minute = datetime.getMinutes()< 10 ? "0" + datetime.getMinutes() : datetime.getMinutes(); 10 var second = datetime.getSeconds()< 10 ? "0" + datetime.getSeconds() : datetime.getSeconds(); 11 return year + "-" + month + "-" + date+" "+hour+":"+minute+":"+second; 12 }
查询数据库时拿到类型为timestamp的时间,封装成json数据格式,通过ajax传至jsp页面时,如果不做任何处理直接显示的话会显示成[object Object];
json封装后的timestamp时间如下:
"createTime":{"date":25,"day":2,"hours":0,"minutes":0,"month":2,"nanos":0,"seconds":0,"time":13956}
其中,参数time即是timestamp中的time属性的值
return的格式可以根据自己的需要进行调整