javaScript 时间转换,将后台返回的时间为一串数字转成正常格式
程序员文章站
2023-10-28 15:48:34
js完整代码: Trust me!! ......
js完整代码:
function transfertime(ctime){
var jsondate = new date(parseint(ctime));
date.prototype.format = function (format){
var o = {
"y+": this.getfullyear(),
"m+": this.getmonth()+1,
"d+": this.getdate(),
"h+": this.gethours(),
"m+": this.getminutes(),
"s+": this.getseconds()
};
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 newdate = jsondate.format("yyyy-mm-dd hh:mm:ss");
return newdate }
trust me!!