javascript Date定义和体验
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta charset="UTF-8">
5 <title>Document</title>
6 </head>
7 <body>
8 <script>
9 //第一种
10 var date1 = new Date();
11 console.log(date1);
12
13 //第二种
14 var date2 = new Date("2018/04/014 00:00:00");
15 console.log(date2);
16
17 //第三种
18 var date3 = new Date(2018,4,14);
19 console.log(date3);
20
21 console.log(date1.getDate()); //获取日1-31
22 console.log(date1.getDay()); //获取星期0-6(0代表周日)
23 console.log(date1.getMonth()); //获取月0-11(0是一月)
24 console.log(date1.getFullYear()); //获取完整年份
25 console.log(date1.getHours()); //获取小时,0-23
26 console.log(date1.getMinutes()); //获取分,0-59
27 console.log(date1.getSeconds()); //获取秒,0-59
28 console.log(date1.getMilliseconds()); //获取毫秒
29 console.log(date1.getTime()); //返回累计毫秒数(从1970/1/1午夜开始)
30 </script>
31 </body>
32 </html>
本文来自博客园,作者:叶子玉,转载请注明原文链接:https://www.cnblogs.com/knuzy/p/8836014.html