运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>JavaScript Dates</h1> <h2>Using Date.now()</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 Date.now() with a year let years = Math.round(Date.now() / year); document.getElementById("demo").innerHTML = years; </script> </body> </html>