zoukankan      html  css  js  c++  java
  • JS 日期

     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>
  • 相关阅读:
    How to call javascript function on page load in asp.net
    How to run a function when the page is loaded?
    JavaScript 查看stack trace
    查看jQuery file upload的image preview如何工作的
    JavaScript-Templates
    Bootstrap 4
    Bootstrap 3 Glyphicons are not working
    WebPack Task Runner
    AMD
    技术干货的选择性问题
  • 原文地址:https://www.cnblogs.com/PowellZhao/p/5575725.html
Copyright © 2011-2022 走看看