码迷,mamicode.com
首页 > Web开发 > 详细

JS 日期

时间:2016-06-11 20:02:37      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:

 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta charset="UTF-8">
 5         <title></title>
 6     </head>
 7     <body>
 8     </body>
 9     
10     <script type="text/javascript">
11         /*日期*/
12         // 创建日期对象
13         // 获取当前时间
14         var nowDate = new Date();
15 //        console.log(nowDate);
16         // 自定义时间日期
17         // 月份从0开始到11
18         var userDate1 = new Date(2017,1,15);
19 //        console.log(userDate1);
20         
21         
22         // tolocalString  电脑是时间
23         console.log(nowDate.toLocaleString());
24         
25         
26         // 1、获取日期的年份
27         var year = nowDate.getFullYear();
28         console.log(year);
29 
30 
31         // 2、获取月份
32         var month = nowDate.getMonth();
33         console.log(month);
34 
35 
36         // 3、获取星期
37         var week = nowDate.getDay();
38         console.log(week);
39 
40 
41         // 4、获取日
42         var day = nowDate.getDate();
43         console.log(day);
44 
45 
46         // 5、获取小时
47         var hour = nowDate.getHours();
48         console.log(hour);
49 
50 
51         // 6、获取分钟
52         var minute = nowDate.getMinutes();
53         console.log(minute);
54 
55 
56         // 7、获取秒
57         var seconds = nowDate.getSeconds();
58         console.log(seconds);
59 
60 
61         // 8、获取距离1970年1月1日0点0分0秒的 毫秒
62         var times = nowDate.getTime();
63         console.log(times);
64         
65     
66     </script>
67     
68 </html>

 

JS 日期

标签:

原文地址:http://www.cnblogs.com/PowellZhao/p/5575725.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!