25_时间对象.html 1017 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <script>
  10. // 时间对象 new Date();
  11. // 时间对象可以用来表示时间
  12. var date = new Date();
  13. // 获取时间对象的年
  14. console.log(date.getFullYear());
  15. // 获取时间对象的月 月份从0开始
  16. console.log((date.getMonth()+1));
  17. // 获取时间对象的天
  18. console.log(date.getDate());
  19. // 获取时间对象的小时
  20. console.log(date.getHours());
  21. // 获取时间对象的分钟
  22. console.log(date.getMinutes());
  23. // 获取时间对象的秒
  24. console.log(date.getSeconds());
  25. // 获取星期 星期天为 0, 星期一为 1, 以此类推
  26. console.log(date.getDay());
  27. // Number对象
  28. var a = 10;
  29. console.log(a.toString());
  30. </script>
  31. </body>
  32. </html>