需求:将后端传来的时间进行转换 原数据: 转化为:
function rTime(date) {
var json_date = new Date(date).toJSON();
return new Date(new Date(json_date) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(
/\.[\d]{3}Z/, '')
}
let date = rTime('2022-03-09T08:04:09.000Z');
console.log(date)
let objectArr = [{
id: 8,
line_id: 1,
mileage: 107517,
roll_id: 654,
time: "2022-03-09T01:04:09.000Z",
type: 15
}, {
id: 8,
line_id: 1,
mileage: 107517,
roll_id: 654,
time: "2022-03-22T08:04:09.000Z",
type: 15
}, {
id: 8,
line_id: 1,
mileage: 107517,
roll_id: 654,
time: "2022-03-11T02:04:09.000Z",
type: 15
}]
let dateObj = objectArr.map(v => ({
...v,
time: (new Date(((new Date(v.time) / 1000) + 8 * 60 * 60) * 1000).toISOString().replace(/T/g,
' ').replace(
/\.[\d]{3}Z/, ''))
}))
console.log(dateObj)
//下载moment
//npm i moment
//main.js引用
// 时间格式转换工具
import moment from 'moment'
Vue.prototype.$moment = moment;
//hoem.vue引用
import moment from "moment";
//方法中使用
changTime(time) {
return moment(time).format("YYYY-MM-DD HH:mm:ss")
},
|