运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,暗/亮
转到 Spaces
<!DOCTYPE html> <html> <body> <h1>JavaScript Dates</h1> <h2>The getTime() Method</h2> <p>Calculate the number of years since January 1, 1970:</p> <p id="demo"></p> <script> // Calculate milliseconds in a year const minute = 1000 * 60; const hour = minute * 60; const day = hour * 24; const year = day * 365; // Divide Time with a year const d = new Date(); let years = Math.round(d.getTime() / year); document.getElementById("demo").innerHTML = years; </script> </body> </html>