时间格式转换,类似于 "2018-07-12T07:45:00.000Z"=>2018 - 07 - 11 15: 45:29

定义:

 // 时间格式转换 "2018-07-12T07:45:00.000Z"=>2018 - 07 - 11 15: 45:29
            format(time, format) {
                var t = new Date(time);
                var tf = function (i) { return (i < 10 ? '0' : '') + i };
                return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function (a) {
                    switch (a) {
                        case 'yyyy':
                            return tf(t.getFullYear());
                            break;
                        case 'MM':
                            return tf(t.getMonth() + 1);
                            break;
                        case 'mm':
                            return tf(t.getMinutes());
                            break;
                        case 'dd':
                            return tf(t.getDate());
                            break;
                        case 'HH':
                            return tf(t.getHours());
                            break;
                        case 'ss':
                            return tf(t.getSeconds());
                            break;
                    }
                })
            },

调用

  this.s_time = this.format(value, 'yyyy-MM-dd');

tip:我在vue中使用的,也可以直接在时间后面添加.split(‘T’)[0]

猜你喜欢

转载自blog.csdn.net/wcy7916/article/details/81178592