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

如题所述

//第一种
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));
温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-07-22
js时间戳怎么转成日期格式 - sufeinet - 博客频道 - CSDN.NET:
http://blog.csdn.net/sufei1013/article/details/8251360
相似回答