时间处理,类似"xxxx-xx-xxTxx:xx:xx187+0000"格式

后端返回的时间:"2020-04-24T09:12:51.187+0000"

目标显示时间:2020-04-24   09:12:51

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
    </head>
    <body>
        <script type="text/javascript">
            
            var time="2020-04-24T09:12:51.187+0000";
            
            
            //某个符号前面的所有
            var wz=time.indexOf("T");
            var res=time.substring(0,wz);
            console.log(res)//年月日
            
            //某个符号后面的所有
            function getCaption(obj){            
                var index=obj.lastIndexOf("\T");
                obj=obj.substring(index+1,obj.length);
                return obj;
            }
            var min=getCaption(time);
            var minwz=min.indexOf(".");
            var minres=min.substring(0,minwz);
            console.log(minres)//时分秒
            
            console.log(res + "\xa0\xa0\xa0" + minres)
            
        </script>
    </body>
</html>

Tips:两个字符串拼接可以用   \xa0    表示空格

 

 

循环给数组对象,添加新的属性

this.navlist.forEach(tem => {
          this.times.forEach(function(val) {
            // console.log(val);
            tem.useTime = val;
          });

          // tem.useTime = 1;
        });
posted @ 2020-05-29 15:39  Rubchinskiy  阅读(748)  评论(0编辑  收藏  举报