时间戳转换为日期格式

如何把长度13位的时间戳转换为这样的格式:2017-04-23 18:55:49

function getTime(t)//t是要转的13位时间戳
var date = new Date(t);
Y = date.getFullYear() + '-';
M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
D = date.getDate() + ' ';
h = date.getHours() + ':';
m = date.getMinutes() + ':';
s = date.getSeconds();
return Y+M+D+h+m+s;
}
希望大家有什么意见或建议,可以指出

猜你喜欢

转载自blog.csdn.net/freeky_ge/article/details/79803335