继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

javaScript 时间转换,将后台返回的时间为一串数字转成正常格式

米脂
关注TA
已关注
手记 492
粉丝 88
获赞 590

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!!

 作者:永无止境-追求致高领域

原文链接:https://www.cnblogs.com/wuliMan/p/10501724.html


打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP