js 日历

getDate()                  获取日 1-31

getDay ()                  获取星期 0-6      

getMonth ()                获取月  0-11

getFullYear ()                 获取完整年份(浏览器都支持)

getHours ()                  获取小时 0-23

getMinutes ()                获取分钟 0-59

getSeconds ()                     获取秒  0-59

getMilliseconds ()            获取当前的毫秒

getTime ()            返回累计毫秒数(1970/1/1午夜)

 

eg:

<!DOCTYPE html>
<html>
 <head>
  <meta charset="UTF-8">
  <title></title>
  <style type="text/css">
   *{
    margin: 0;
    padding: 0;
   }
   .box{
    width: 150px;
    height: 180px;
    margin: 100px auto;
    background-color: lightpink;
   }
   .box p{
    font-size: small;
   }
   .box span{
    display: block;
    width: 70px;
    height: 70px;
    margin: 30px auto;
    font-size: 50px;
    color: white;
    background-color: hotpink;
   }
  </style>
  <script>
   window.onload = function(){
   var box = document.getElementById('box');
   var child = box.children;
   var date = new Date();
   var arr = ['星期日','星期一','星期二','星期三','星期四','星期五','星期六']
   child[0].innerHTML = '今天是'+date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate()+'  '+arr[date.getDay()];
   child[1].innerHTML = date.getDate();
  }
  </script>
 </head>
 <body>
   <div class="box" id="box">
    <p></p>
    <span></span>
   </div>
 </body>
</html>

posted @ 2018-03-10 11:08  丢嫂  阅读(143)  评论(0编辑  收藏  举报