1.如果是13位时间戳
function getdate() {
var now = new Date(),
y = now.getFullYear(),
m = ("0" + (now.getMonth() + 1)).slice(-2),
d = ("0" + now.getDate()).slice(-2);
return y + "-" + m + "-" + d + " " + now.toTimeString().substr(0, 8);
}
2.如果是10位到秒的
需要乘以1000
<html>
<body>
<script type="text/javascript">
function getdate(stmp) {
var now = new Date(stmp*1000),
y = now.getFullYear(),
m = ("0" + (now.getMonth() + 1)).slice(-2),
d = ("0" + now.getDate()).slice(-2);
return y + "-" + m + "-" + d + " " + now.toTimeString().substr(0, 8);
}
alert(getdate(1547551970))
</script>>
</body>>
</html>