JavaScript輸出當前時間Unix時間戳的方法

字號:


    具體如下:
    下面的代碼通過Date對象的getTime()放回unix時間戳,即從1970年1月1日到當前時間的秒數(shù)
    <!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>