<script >
//时间转换(js将 “2021-07-06T06:23:57.000+00:00” 转换为年月日时分秒)
function transformTimestamp(timestamp) {
let a = new Date(timestamp).getTime();
const date = new Date(a);
const Y = date.getFullYear() + '-';
const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
const D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
const h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
const m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes());
// const s = date.getSeconds(); // 秒
const dateString = Y + M + D + h + m;
// console.log('dateString', dateString); // > dateString 2021-07-06 14:23
return dateString;
}
let arr1=[
{
id:1,
name:'张三',
details:[
{
id:2,
time:'2022-07-28T17:03:12.000Z'
},
{
id:3,
time:'2022-07-29T17:03:12.000Z'
}
]
},
{
id:2,
name:'李四',
details:[
{
id:2,
time:'2022-08-28T17:03:12.000Z'
},
{
id:3,
time:'2022-04-29T17:03:12.000Z'
}
]
}
]
for(var i=0;i<arr1.length;i++){
for(var j=0;j<arr1[i].details.length;j++){
arr1[i].details[j].time=transformTimestamp(arr1[i].details[j].time);
}
}
</script>