使用 getDay() 以及一个数组以名称显示星期名
- <!DOCTYPE html>
- <html>
- <body>
- <h2>JavaScript getDay()</h2>
- <p>getDay() 方法将周名作为数字返回:</p>
- <p>您可以使用数组来显示星期的名称:</p>
- <p id="demo"></p>
- <script>
- var d = new Date();
- var days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
- document.getElementById("demo").innerHTML = days[d.getDay()];
- </script>
- </body>
- </html>