时间方法封装 ->untils->time.ts
const getTimeLabel=(row:any,column:any,cellValue:any,index:any)=>{
let format = 'YYYY-mm-dd HH:MM:SS'
let date = new Date(cellValue);
const dataItem = {
'Y+': date.getFullYear().toString(),
'm+': (date.getMonth() + 1).toString(),
'd+': date.getDate().toString(),
'H+': date.getHours().toString(),
'M+': date.getMinutes().toString(),
'S+': date.getSeconds().toString(),
};
Object.keys(dataItem).forEach((item) => {
const ret = new RegExp(`(${item})`).exec(format);
if (ret) {
format = format.replace(ret[1], ret[1].length === 1 ? dataItem[item] : dataItem[item].padStart(ret[1].length, '0'));
}
});
return format
}
export function timeFormatter(row:any,column:any,cellValue:any,index:any):any {
return getTimeLabel(row,column,cellValue,index)
}
<el-table-column property="create_time" label="充值日期" :formatter="timeFormatter" />