最近做的一个项目,从后台查询到日期数据传到前台JS中遍历之后显示的是以"14"开头的毫秒数,刚开始想用"simpleDateFormat"类处理,结果显示都不显示了。后来查了一下资料,感觉其实很简单,下面 把自己的方法分享给大家以供参考。
1.显示的毫秒数
2.处理之前的样式
3.处理之后的样式
Date.prototype.toLocaleString = function() {
return this.getFullYear() + "-" + (this.getMonth() + 1) + "-" + this.getDate() + " " + this.getHours() + ":" + this.getMinutes() + ":" + this.getSeconds();
};
success:function(data){
var Str="";
var length = data.length;
for(var i=0;i<length;i++){
//Str += '<tr><td>'+data[i].roleId+'</td><td>'+data[i].roleName+'</td><td>'+data[i].remarks+'</td><td>'+data[i].createBy+'</td><td>'+data[i].createDate+'</td><td>'+data[i].updateBy+'</td><td>'+data[i].updateDate+'</td><td>'+data[i].status+'</td></tr>';
Date.prototype.toLocaleString = function() {
return this.getFullYear() + "-" + (this.getMonth() + 1) + "-" + this.getDate() + " " + this.getHours() + ":" + this.getMinutes() + ":" + this.getSeconds();
};
Str += "<tr>" +
"<td class=\"tbody_check\">" +
"<span class=\"check\">" +
"<input type=\"checkbox\" value=\""+data[i].roleId+"\" name=\"checkbox\">" +
"</span>" +
"</td>" +
"<td>" +data[i].roleId+"</td>" +
"<td>" +data[i].roleName+"</td>" +
"<td>" +data[i].remarks+"</td>" +
"<td>" +data[i].createBy+"</td>" +
"<td>" +new Date(data[i].createDate).toLocaleString()+"</td>" +
"<td>" +data[i].updateBy+"</td>" +
"<td>" +new Date(data[i].updateDate).toLocaleString()+"</td>" +
"<td>" +data[i].status+"</td>" +
"</tr>";
}
$("#rolelist").html(Str);
}