W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <p>单击该按钮可显示指定日期与 1970 年 1 月 1 日之间的年数。</p> <button onclick="myFunction()">试一试</button> <p id="demo"></p> <script> function myFunction() { var d = Date.parse("March 21, 2012"); var minutes = 1000 * 60; var hours = minutes * 60; var days = hours * 24; var years = days * 365; var y = Math.round(d / years); document.getElementById("demo").innerHTML = y; } </script> </body> </html>