JS时间戳转YY-MM-DD,标准时间转YY-MM-DD

		var timestamp= 1569859200000;
		let date = new Date(timestamp);
		let y = date.getFullYear();
		let MM = date.getMonth() + 1;
		MM = MM < 10 ? ('0' + MM) : MM;
		let d = date.getDate();
		d = d < 10 ? ('0' + d) : d;
		let h = date.getHours();
		h = h < 10 ? ('0' + h) : h;
		let m = date.getMinutes();
		m = m < 10 ? ('0' + m) : m;
		let s = date.getSeconds();
		s = s < 10 ? ('0' + s) : s;
		var str = y +'-'+MM+'-'+d+'-'+h +'-'+m+'-'+s;
		console.log(str)

时间戳:1569859200000
输出:2019-10-01-00-00-00

var time = new Date();
time=new Date(+new Date(time) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
console.log(time)

标准时间:Thu Oct 10 2019 17:41:29 GMT+0800 (中国标准时间)
输出:2019-10-10 17:41:29

更多请点击:js时间转化方法

你可能感兴趣的:(js)