分析原因:
在IE浏览器中,只有字符串格式的"/“能正常解析,”,“和”-"都不能。
IE11不能正常解析的时间:2020-09-29T00:00:00.000+0800
解决方法:
全局注册一个时间过滤器
1.在filters文件夹下面,创建一个tsDate1.js文件
const tsDate1 = function dateFormat(date, format) {
if (arguments.length === 0) {
return null
}
if (date === null) {
return ''
}
if (date && typeof (date) === 'string') {
date = date.replace(/\+[\d]{4}/, '')
// console.log(date,'222222222222')
}
date = new Date(date);
if (!date || date.toUTCString() == "Invalid Date") {
return "";
}
var map = {
"M": date.getMonth() + 1, //月份
"D": date.getDate(), //日
"H": date.getHours(), //小时
"m": date.getMinutes(), //分
"s": date.getSeconds(), //秒
"q": Math.floor((date.getMonth() + 3) / 3), //季度
"S": date.getMilliseconds() //毫秒
};
format = format.replace(/([YMDHmsqS])+/g, function(all, t) {
var v = map[t];
if (v !== undefined) {
if (all.length > 1) {
v = '0' + v;
v = v.substr(v.length - 2);
}
return v;
} else if (t === 'Y') {
return (date.getFullYear() + '').substr(4 - all.length);
}
return all;
});
return format;
}
export default {
tsDate1
}
2.在main.js中自定义一个全局过滤器
// 自定义过滤器
import Filters from './filters/tsDate1'
Object.keys(Filters).forEach(key => Vue.filter(key, Filters[key]))
3.在组件使用,得到任何自己想要的格式
<span>{{ scope.row.effectTime | tsDate1('YYYY-MM-DD HH:mm:ss') }}</span>