首页 > 其他 > 详细

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

时间:2020-05-29 16:47:14      阅读:113      评论:0      收藏:0      [点我收藏+]

后端返回的时间:"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;
        });

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

原文:https://www.cnblogs.com/zhouying1208/p/12987768.html

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