1.原格式:2024-04-16T16:19:23 转换为 2024/04/16
代码:
console.log(item.createTime,'切割前');
item.createTime = item.createTime ? item.createTime.split('T')[0].replace(/-/g, "/") : item.createTime
console.log(item.createTime,'切割后并转换格式');
2.原格式: 2024-04-16T16:19:23 转换为 2024-04-16 16:19:23
代码:
function convertTimeFormat(isoTime) {
const date = new Date(isoTime);
const year = date.getFullYear();
const month = (date.getMonth() + 1).toString().padStart(2, '0');
const day = date.getDate().toString().padStart(2, '0');
const hours = date.getHours().toString().padStart(2, '0');
const minutes = date.getMinutes().toString().padStart(2, '0');
const seconds = date.getSeconds().toString().padStart(2, '0');
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}
item.createTime = item.createTime ? convertTimeFormat( item.createTime ) : item.createTime
item.updateTime = item.updateTime? convertTimeFormat( item.updateTime) : item.updateTime