xinxinxiangrong7

 写一个转换时间格式的公用方法:

将\'2019-5-6 16:30:02’ 转换成 2019年05月06日 16时30分02秒

~function(pro){
       pro.formatTime=function(template){
           template=template || \'{0}年{1}月{2}日 {3}时{4}分{5}秒\';
           var ary=this.match(/\d+/g);
           template=template.replace(/\{(\d+)\}/g,function (){
               var n=arguments[1],
                  val=ary[n] || \'0\';
                  val<10?val= \'0\'+val:null;
                  return val;
           });
           return template;
           
       }
   }(String.prototype)

var str=\'2019-5-6 16:30:02;
str.formatTime();//2019年05月06日 16时30分02秒

 

分类:

技术点:

相关文章: