js時間戳轉成日期格式
阿新 • • 發佈:2018-07-21
parse sub subst ace cal 三種 date ring localtime
//第一種 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));
js時間戳轉成日期格式