JavaScript倒计时器

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Title</title>
 6     <script>
 7 //        倒计时
 8         function timerCount() {
 9             var today = new Date();
10             var year = today.getFullYear();
11             var someday = new Date(2016, 12, 1, 1, 23, 59);
12             var time = (someday - today) / 1000;
13             var day = Math.floor(time / (60 * 60 * 24));
14             var hour = Math.floor(time % (60 * 60 * 24) / (60 * 60));
15             var min = Math.floor(time % (60 * 60 * 24) % (60 * 60) / 60);
16             var sec = Math.floor(time % (60 * 60 * 24) % (60 * 60) % 60);
17 
18             function double(value) {
19                 return value < 10 ? "0" + value : value;
20             }
21 
22             var timeStr = "还剩下" + double(day) + "" + double(hour) + "" + double(min) + "" + double(sec) + "";
23             console.log(timeStr);
24         }
25         setInterval(function () {
26             timerCount();
27         }, 1000);
28     </script>
29 </head>
30 <body>
31 </body>
32 </html>

 

posted @ 2016-01-13 22:56  Farris  阅读(336)  评论(0编辑  收藏  举报