使用 getDay() 以及一个数组以名称显示星期名

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h2>JavaScript getDay()</h2>
  6.  
  7. <p>getDay() 方法将周名作为数字返回:</p>
  8.  
  9. <p>您可以使用数组来显示星期的名称:</p>
  10.  
  11. <p id="demo"></p>
  12.  
  13. <script>
  14. var d = new Date();
  15. var days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
  16. document.getElementById("demo").innerHTML = days[d.getDay()];
  17. </script>
  18.  
  19. </body>
  20. </html>