js需要把時間戳轉(zhuǎn)為為普通格式,一般的情況下可能用不到的,
下面先來看第一種吧
function getLocalTime(nS) { return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:/d{1,2}$/,' '); } alert(getLocalTime(1293072805)); 第二種
function getLocalTime(nS) { return new Date(parseInt(nS) * 1000).toLocaleString().substr(0,17)} alert(getLocalTime(1293072805)); 正則替換
function getLocalTime(nS) { return new Date(parseInt(nS) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " "); } alert(getLocalTime(1177824835)); 第三種
function formatDate(now) { var year=now.getYear(); var month=now.getMonth()+1; var date=now.getDate(); var hour=now.getHours(); var minute=now.getMinutes(); var second=now.getSeconds(); return year+"-"+month+"-"+date+" "+hour+":"+minute+":"+second; } var d=new Date(1230999938); alert(formatDate(d)); 以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。
新聞熱點
疑難解答