zoukankan      html  css  js  c++  java
  • 转 javascript 倒计时显示当年剩下的天时分秒

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>一道JS面试题</title>
    <style>
    body
    {
     font-size
    :12px;
     font-family
    :"微软雅黑";
     line-height
    :1.8;
    }
    </style>
    </head>

    <body>
    <h3>一道JS大面试题</h3>
    <p>题目在网页里倒计时显示当年剩下的天时分秒,格式:XX年还剩下X天X时X分X秒</p>
    <div id="m1"></div>
    <script type="text/javascript">
    (
    function(){
     
    var day=hour=minitus=second=ms=0;
     
    var year=new Date().getFullYear()+1;
     
    var tmp=new Date(year,0,1)-new Date();
     day
    =Math.floor(tmp/86400000);
     (function(){
      tmp
    =(new Date(year,0,1)-new Date())%86400000;
      hour
    =Math.floor(tmp/3600000);
      tmp%=3600000;
      minitus
    =Math.floor(tmp/60000);
      tmp%=60000;
      second
    =Math.floor(tmp/1000);
      ms=tmp-1000*second;
      
      document.getElementById(
    "m1").innerHTML="距离"+year+"年还有 "+day+" 天 "+hour+" 小时 "+minitus+" 分 "+second+" 秒 "+ms;
      setTimeout(arguments.callee,
    50);
     })();
    })();
    </script>
    </body>
    </html>

  • 相关阅读:
    LightOJ 1030 Discovering Gold(期望)
    CodeForces 567B Berland National Library
    HDU
    HDU
    (模拟、进制转换)
    HDU
    HDU
    CodeForces 429 B B. Working out
    CodeForces 546 D. Soldier and Number Game(素数有关)
    2016中国大学生程序设计竞赛
  • 原文地址:https://www.cnblogs.com/zwei1121/p/1796378.html
Copyright © 2011-2022 走看看