本文實例講述了JavaScript輸出當前時間Unix時間戳的方法。分享給大家供大家參考。具體如下:
下面的代碼通過Date對象的getTime()放回unix時間戳,即從1970年1月1日到當前時間的秒數
<!DOCTYPE html>
<html>
<body>
<p id="demo">
Click the button to display the number
of milliseconds since midnight,
January 1, 1970.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction()
{
var d = new Date();
var x = document.getElementById("demo");
x.innerHTML=d.getTime();
}
</script>
</body>
</html>
希望本文所述對大家的javascript程序設計有所幫助。