js时间戳转年月日时分秒格式,一行代码搞定

293 阅读1分钟

拿到接口返回的数据,如果是list就循环,不是直接用即可

for (let i = 0; i < this.cqjyggList.length; i++) {   
    //先确认时间戳是不是Number类型,不是就转成Number类型
    const timestamp = Number(this.cqjyggList[i].endTime)
    // 转成Number类型之后通过new Date(时间戳)..toLocaleString()转换即可
    this.cqjyggList[i].endTime = new Date(timestamp).toLocaleString()
                        }