本文實例講述了JS自定義函數實現時間戳轉換成date的方法。分享給大家供大家參考,具體如下:
<!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>獲取當前年/月/日(m.survivalescaperooms.com)</title></head><body><script>function UnixToDate(unixTime, timeZone) { if (typeof (timeZone) == 'number') { unixTime = parseInt(unixTime) + parseInt(timeZone) * 60 * 60; } var now = new Date(unixTime * 1000); var year=now.getFullYear(); var month=now.getMonth()+1; var date=now.getDate(); var hour=now.getHours(); var minute=now.getMinutes(); return year+"/"+month+"/"+date+" "+hour+":"+minute ;}var m_time = parseInt(new Date().getTime()/1000); var m_date = UnixToDate(m_time) ;document.write(m_date);</script></body></html>運行結果:
2017/8/27 12:4
希望本文所述對大家JavaScript程序設計有所幫助。
新聞熱點
疑難解答