JavaScript基础17——js的Date对象

 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta charset="UTF-8">
 5         <title>js的Date对象</title>
 6         <script type="text/javascript">
 7             var date = new Date();
 8             document.write("当前日期:" + date);
 9             // toLocaleString()方法,根据本地时间格式,把Date对象转换为字符串
10             document.write("<br />格式化 toLocaleString()方法:" + date.toLocaleString());
11             // getFullYear()方法,得到当前的四位数年份
12             document.write("<br />年份 getFullYear():" + date.getFullYear());
13             // getMonth()方法,得到当前的月份(0-11)
14             document.write("<br />月份 getMonth():" + (date.getMonth() + 1));
15             // getDay()方法,得到当前的星期(0-6),外国朋友把星期日作为一周的第一天,所以星期日返回0
16             document.write("<br />星期 getDay():" + date.getDay());
17             // getDate()方法,得到当前的日(1-31)
18             document.write("<br />日 getDate():" + date.getDate());
19             // getHours()方法,得到当前的小时(0-23)
20             document.write("<br />小时 getHours():" + date.getHours());
21             // getMinutes()方法,得到当前的分钟(0-59)
22             document.write("<br />分钟 getMinutes():" + date.getMinutes());
23             // getSeconds()方法,得到当前的秒钟(0-59)
24             document.write("<br />秒钟 getSeconds():" + date.getSeconds());
25             // getMilliseconds()方法,得到当前的毫秒(0-999)
26             document.write("<br />毫秒 getMilliseconds():" + date.getMilliseconds());
27             // getTime()方法,获取1970年1月1日至今的毫秒数
28             /* 
29                使用毫秒数处理缓存的效果(没有缓存)
30                http://www.baidu.com?getTime()的值
31              */
32             document.write("<br />1970年1月1日至今的毫秒数 getTime():" + date.getTime());
33         </script>
34     </head>
35     <body>
36     
37     </body>
38 </html>

原文地址:https://www.cnblogs.com/linyisme/p/5865309.html