在JS中如何把毫秒转换成规定的日期时间格式实例
最近做的一个项目,从后台查询到日期数据传到前台JS中遍历之后显示的是以"14"开头的毫秒数,刚开始想用"simpleDateFormat"类处理,结果显示都不显示了。后来查了一下资料,感觉其实很简单,下面 把自己的方法分享给大家以供参考。
创新互联公司是一家专业提供额济纳企业网站建设,专注与网站设计制作、成都网站制作、H5高端网站建设、小程序制作等业务。10年已为额济纳众多企业、政府机构等服务。创新互联专业网络公司优惠进行中。
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'+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);
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持创新互联。
本文名称:在JS中如何把毫秒转换成规定的日期时间格式实例
当前地址:http://www.jxjierui.cn/article/pjchoj.html


咨询
建站咨询
