JS时间戳转YY-MM-DD

方法1

new Date(parseInt(‘时间戳’) * 1000).toLocaleString().replace(/:\d{1,2}$/,' ')

例:将1568168403转化为时间
console.log(new Date(parseInt(1568168403) * 1000).toLocaleString().replace(/:\d{1,2}$/,' '));

输出结果: 2019/9/11 上午10:20
JS时间戳转YY-MM-DD_第1张图片
方法2

封装函数times

function times(value) {
     var date = new Date(parseInt(value) * 1000)
     var tt = [date.getFullYear(), date.getMonth() + 1, date.getDate()].join('-') + '  ' + [date.getHours(), date.getMinutes()].join(':');
     return tt;
}

//例:将1568168403转化为时间       
	  
	  times(1568168403);

即可转化为 2019-9-11 10:20

你可能感兴趣的:(js)