1.src同级建commFunction=》timer.js
2.main.js引入
import time from '../commonFunction/time'
Vue.prototype.time=time
=======================================
情况一1.时间戳
// 时间戳转时间 2020-4-24 00:30:00
timeStamp(val) {
val = val.toString()
if(val.length == 10) {
let time = val * 1000;
let timestamp4 = new Date(time);
return (timestamp4.toLocaleDateString().replace(///g, "-") +" " + timestamp4.toTimeString().substr(0, 8));
} else {
let timestamp4 = new Date(val);
return (timestamp4.toLocaleDateString().replace(///g, "-") +" " +timestamp4.toTimeString().substr(0, 8));
}
},
// 2017-4-8 14:11:33转2017-04-08 14:11:33
handeldate(m){
let o = m[0]+m[1]+m[2]+m[3]
if(m.length==18){
if(m[6]=='-'){
return o+m[4]+'0'+m[5]+m[6]+m[7]+m[8]+m.slice(9)
}
if(m[7]=='-'){
return o+m[4]+m[5]+m[6]+m[7]+'0'+m[8]+m.slice(9)
}
}else if(m.length==17){
return o+m[4]+'0'+m[5]+m[6]+'0'+m[7]+m.slice(8)
}else{
return m
}
}
页面使用:
appList.forEach(element => {
element.create_time = this.time.handeldate(this.time.timeStamp(element.create_time))
});