怎么把后台传过来的时间戳转换为想要的格式:
首先来看一下什么是时间戳:
后台传回来的时间戳格式:1544512821
通过下面的方式就可以转换为我们想要的格式: 2018年12月11日 15:20
var date = new Date(item.createtime*1000); //item.creatime 就是后台请求回来的数据 1544512821
var Y = date.getFullYear() + '年';
var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '月';
var D = date.getDate();
D = D<10?'0'+D+ '日'+' ':D+ '日'+' '
var h = date.getHours();
h = h < 10 ? '0' + h + ':' : h + ':'
var m = date.getMinutes();
m = m < 10 ? '0' + m : m
item.createtime =Y + M + D + h + m
这样,通过这种方式就转换为我们想要的格式了,
转换后的样式: