https://blog.csdn.net/lianfengzhidie/article/details/80890715 JS将毫秒时间转换成本地时间去掉TZ 

function myformatdate(inputTime){
	if(!inputTime && typeof inputTime !== 'number'){
		return '';
	}
	var localTime = '';
	inputTime = new Date(inputTime).getTime();
	const offset = (new Date()).getTimezoneOffset();
	localTime = (new Date(inputTime - offset * 60000)).toISOString();
	localTime = localTime.substr(0, localTime.lastIndexOf('.'));
	localTime = localTime.replace('T', ' ');
	return localTime;
}

改:Vue中

res.data.list.forEach((item) => {
      item.createDate = this.myformatdate(item.createDate);
 });
this.tableData = res.data.list;

myformatdate(inputTime){
	if(!inputTime && typeof inputTime !== 'number'){
		return '';
	}
	var localTime = '';
	inputTime = new Date(inputTime).getTime();
	const offset = (new Date()).getTimezoneOffset();
	localTime = (new Date(inputTime - offset * 60000)).toISOString();
	localTime = localTime.substr(0, localTime.lastIndexOf('.'));
	localTime = localTime.replace('T', ' ');
	return localTime;
},

或者 
export function myformatdate(inputTime){
	if(!inputTime && typeof inputTime !== 'number'){
		return '';
	}
	var localTime = '';
	inputTime = new Date(inputTime).getTime();
	const offset = (new Date()).getTimezoneOffset();
	localTime = (new Date(inputTime - offset * 60000)).toISOString();
	localTime = localTime.substr(0, localTime.lastIndexOf('.'));
	localTime = localTime.replace('T', ' ');
	return localTime;
},

运行结果:

console.log(myTimeToLocal(1530540726443));

2018-07-02 22:12:06
console.log(myTimeToLocal('2017-11-16T05:23:20.000Z'));

2017-11-16 13:23:20
Logo

前往低代码交流专区

更多推荐