运行 ❯
获取您的
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h2>JavaScript Dates</h2> <p>parse() parses a date string and returns the number of milliseconds since midnight January 1, 1970.</p> <p>Calculate the number of years between March 21, 2012 and 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; // Compute years const d = Date.parse("March 21, 2012"); let years = Math.round(d / year); document.getElementById("demo").innerHTML = years; </script> </body> </html>