js时间戳转成日期格式

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

猜你喜欢

转载自www.cnblogs.com/web-chuanfa/p/9345775.html