2021/9/13
获取时间
<body> <p id="demo">获取今年的年份。</p> <button onclick="myFunction()">点击</button> <script> function myFunction(){ var d = new Date(); var x = document.getElementById("demo"); x.innerHTML=d.getFullYear(); } </script> </body>
<body> <p id="demo">单击按钮显示毫秒数。</p> <button onclick="myFunction()">...</button> <script> function myFunction(){ var d = new Date(); var x = document.getElementById("demo"); x.innerHTML=d.getTime(); } </script> </body>
<body> <p id="demo">单击按钮显示修改后的年月日。</p> <button onclick="myFunction()">按钮</button> <script> function myFunction(){ var d = new Date(); d.setFullYear(2020,10,3); var x = document.getElementById("demo"); x.innerHTML=d; }