最近做的一个项目,从后台查询到日期数据传到前台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
//Str += '
'+data[i].roleId+''+data[i].roleName+''+data[i].remarks+''+data[i].createBy+''+data[i].createDate+''+data[i].updateBy+''+data[i].updateDate+''+data[i].status+'';Date.prototype.toLocaleString = function() {
return this.getFullYear() + "-" + (this.getMonth() + 1) + "-" + this.getDate() + " " + this.getHours() + ":" + this.getMinutes() + ":" + this.getSeconds();
};
Str += "
" +"
" +"" +
"" +
"" +
"
" +"
" +data[i].roleId+"" +"
" +data[i].roleName+"" +"
" +data[i].remarks+"" +"
" +data[i].createBy+"" +"
" +new Date(data[i].createDate).toLocaleString()+"" +"
" +data[i].updateBy+"" +"
" +new Date(data[i].updateDate).toLocaleString()+"" +"
" +data[i].status+"" +"
";}
$("#rolelist").html(Str);
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。