首页 > 其他 > 详细

转换时间格式的方法

时间:2019-08-29 22:02:25      阅读:76      评论:0      收藏:0      [点我收藏+]

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

将‘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秒

 

转换时间格式的方法

原文:https://www.cnblogs.com/xinxinxiangrong7/p/11432220.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!