码迷,mamicode.com
首页 > 其他好文 > 详细

倒计时

时间:2020-01-11 18:17:39      阅读:70      评论:0      收藏:0      [点我收藏+]

标签:cal   gets   inter   idt   int   code   tin   doctype   document   

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    h1{
      text-align: left;
      color: chartreuse;
    }
  </style>
</head>

<body>
  <h1 id="h1"><span id="ab1"></span></h1 >
  <h2 id="h1"><span id="ab2"></span></h2>
  <h3 id="h1"> 新年剩余:<span id="ab3"></span></h3>

  <script>
      

      
    function fn() {
      bb1 = document.getElementById(‘ab1‘)
      bb2 = document.getElementById(‘ab2‘)
      bb3 = document.getElementById(‘ab3‘)
      let a1 = new Date()
      let a2 = a1.getFullYear();//
      let a3 = a1.getMonth()+1;//
      let aa1 = a1.getDay();//星期
      let a4 = a1.getDate();//
      let a5 = a1.getHours();//
      let a6 = a1.getMinutes();//
      let a7 = a1.getSeconds();//
      let a8 = a1.getMilliseconds();//毫秒

      var b1 = new Date(2020, 1-1, 23, 23, 59, 59);
      var time = (b1 - a1) / 1000;
      var c2 = Math.floor(time / (24 * 60 * 60))
      var c3 = Math.floor(time % (24 * 60 * 60) / (60 * 60))
      var c4 = Math.floor(time % (24 * 60 * 60) % (60 * 60) / 60);
      var c5 = Math.floor(time % (24 * 60 * 60) % (60 * 60) % 60);     
      bb1.innerHTML = a2 + ‘年‘+ a3 + ‘月‘ + a4 + ‘日‘ +  ‘-‘ + ‘星期‘ + aa1 
      bb2.innerHTML = a5 + ‘时‘ + a6 + ‘分‘ +  ‘:‘ + a7 + ‘秒‘ + a8 + ‘毫秒‘
      bb3.innerHTML =  c2 + ‘日‘  + c3 + ‘时‘+ c4 + ‘分‘ + c5 + ‘秒‘ 
    }
    var timer=setInterval(fn, 1000)
  </script>
</body>
</html>

倒计时

标签:cal   gets   inter   idt   int   code   tin   doctype   document   

原文地址:https://www.cnblogs.com/penggedeboke1999/p/12180594.html

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