js時間戳轉爲日期格式

這個在(日期類型爲datetime)+ajax的時候才能用到,js須要把時間戳轉爲爲普通格式,通常的狀況下可能用不到。 ajax


Js代碼: spa

<script>
function getLocalTime(nS) {
    return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/,' ');
}
alert(getLocalTime(1293072805));
</script>

彈出格式:   2010年12月23日 10:53 code

也能夠用: ip

Js代碼: get

<script>
function getLocalTime(nS) {
    return new Date(parseInt(nS) * 1000).toLocaleString().substr(0,17)}
alert(getLocalTime(1293072805));
</script>

若是想彈出:2010-10-20 10:00:00這個格式的也好辦 io

Js代碼: function

<script>
function getLocalTime(nS) {
    return new Date(parseInt(nS) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " "); 
}
alert(getLocalTime(1177824835));
</script>
相關文章
相關標籤/搜索