zoukankan      html  css  js  c++  java
  • JS-Date日期内置对象

      1、基本用法

    <script>
          var date = new Date();
          document.write(date+"<br/>");//获取具体时间
          
          document.write(date.getFullYear()+"<br/>");//获取年份
          document.write(date.getTime()+"<br/>");//获取1970年至今毫秒数
          date.setFullYear(2010, 1, 1);
          document.write(date+"<br/>");  //自己设置时间
          
       </script>

      2、实现简单的时钟操作

     1 <!DOCTYPE html>
     2 <html>
     3 <head>
     4 <meta charset="UTF-8">
     5 <title>uvi</title>
     6      <link rel="stylesheet" href="style.css" type="text/css">
     7 </head>
     8 <body onload="startTime()">
     9    <script>
    10       /*  实现简单的时钟操作  */
    11       function startTime(){
    12           var today = new Date();
    13           var h = today.getHours();
    14           var m = today.getMinutes();
    15           var s = today.getSeconds();
    16           m = checkTime(m);
    17           s = checkTime(s);
    18           document.getElementById("timetxt").innerHTML = h+":"+m+":"+s;
    19           t = setTimeout(function(){
    20              startTime(); 
    21           },500);
    22       }
    23       function checkTime(i){//如果是个位数,在前面补"0"
    24           if(i<10){
    25               i="0"+i;
    26           }
    27           return i;
    28       }
    29       
    30    </script>
    31    <div id = "timetxt"></div>
    32    
    33 </body>
    34 </html>
  • 相关阅读:
    架构资料
    Node参考资料
    运维参考资料
    前端参考资料
    Python参考资料
    推荐几个工具型网站
    学好Mac常用命令,助力iOS开发
    git submodule相关操作
    HttpURLConnection传JSON数据
    【树莓派笔记3】安装配置samba 和Windows进行文件共享
  • 原文地址:https://www.cnblogs.com/UniqueColor/p/5755586.html
Copyright © 2011-2022 走看看