时间格式转换

格式化时间

 1 <script type="text/javascript">
 2     //格式化时间格式的字符串
 3     String.prototype.myTimes = function () {
 4         var reg = /^(d{4})(?:-|/|.|:)(d{1,2})(?:-|/|.|:)(d{1,2})(?:s+)(d{1,2})(?:-|/|.|:)(d{1,2})(?:-|/|.|:)(d{1,2})$/;
 5         var ary = [];
 6         this.replace(reg, function () {
 7             ary = ([].slice.call(arguments)).slice(1, 7);
 8         });
 9         var format = arguments[0];//格式是{0}年{1}月{2}日 {3}:{4}:{5}
10         return format.replace(/{(d+)}/g, function () {
11             var val = ary[arguments[1]];
12             return val.length === 1 ? "0" + val : val;
13         })
14     };
15     var str = "2015-2-3 2:26:36";
16     var con = str.myTimes("{0}年{1}月{2}日 {3}:{4}:{5}");
17     console.log(con)//2015年02月03日 02:26:36
18 </script>
原文地址:https://www.cnblogs.com/wuxianqiang/p/6435648.html