在uni-app中使用如下的过滤器
{{sj | dateFormat('HH:mm')}}
在Chrome调试时工作正常。但在iOS调试时总是显示为0。
过滤器内容如下:
Vue.filter('dateFormat', function(value, format) {
if (value==undefined) {
return '';
}
let s=(''+value+',,,,,,').replace(/-/g, ',').replace(/\:/g, ',').replace(/./g, ',').replace(/T/g, ',').replace(/\//g, ',').replace(/ /, ',');
let a=s.split(',');
if (!format) {
format='yyyy-MM-dd hh:mm';
}
var o = {
"M+" : a[1], //month
"d+" : a[2], //day
"h+" : a[3], //hour
"H+" : a[3], //hour
"m+" : a[4], //minute
"s+" : a[5], //second
"S" : a[6] //millisecond
}
if(/(y+)/.test(format)) {
format=format.replace(RegExp.$1, (a[0]+"").substr(4 - RegExp.$1.length));
}
for(var k in o) {
if(new RegExp("("+ k +")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
}
}
return format;
});
1 个回复
Trust - 少说废话
App 上不支持这种写法
不支持部分复杂的 JavaScript 渲染表达式