- 根据后台返回的时间戳转为日期型格式
// 时间戳转日期格式
formatDate(now) {
var year=now.getFullYear(); //取得4位数的年份
var month=now.getMonth()+1; //取得日期中的月份,其中0表示1月,11表示12月
var date=now.getDate(); //返回日期月份中的天数(1到31)
var hour=now.getHours(); //返回日期中的小时数(0到23)
var minute=now.getMinutes(); //返回日期中的分钟数(0到59)
var second=now.getSeconds(); //返回日期中的秒数(0到59)
return year+"-"+month+"-"+date+" "+hour+":"+minute+":"+second;
}
调用
let a = new Date(this.dataList[i].time); //定义一个变量a定义要转换的时间格式,this.dataList[i].time是后台返回过来的时间戳
this.dataList[i].time = this.formatDate(a)
https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/e99aef2671c748ddb61406e992324798~tplv-k3u1fbpfcp-zoom-1.image?imageView2/2/w/480/h/480/q/85/interlace/1