js时间戳怎么转成日期格式

2025-02-24 06:47:28
推荐回答(2个)
回答1:

//第一种
function getLocalTime(nS) {
return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/,' ');
}
alert(getLocalTime(1293072805));
//结果是2010年12月23日 10:53//第二种
function getLocalTime(nS) {
return new Date(parseInt(nS) * 1000).toLocaleString().substr(0,17)
}
alert(getLocalTime(1293072805));//第三种 格式为:2010-10-20 10:00:00
function getLocalTime(nS) {
return new Date(parseInt(nS) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
}
alert(getLocalTime(1177824835));

回答2:

js时间戳怎么转成日期格式 - sufeinet - 博客频道 - CSDN.NET:
http://blog.csdn.net/sufei1013/article/details/8251360