• 倒计时


    倒计时部分代码:

    <script>
    function FreshTime()
    {
    var endtime=new Date("2016/10/15,12:20:12");//结束时间
    var nowtime = new Date();//当前时间
    var lefttime=parseInt((endtime.getTime()-nowtime.getTime())/1000);
    d=parseInt(lefttime/3600/24);
    h=parseInt((lefttime/3600)%24);
    m=parseInt((lefttime/60)%60);
    s=parseInt(lefttime%60);

    document.getElementById("LeftTime").innerHTML=d+"天"+h+"小时"+m+"分"+s+"秒";
    if(lefttime<=0){
    document.getElementById("LeftTime").innerHTML="团购已结束";
    clearInterval(sh);
    }
    }
    FreshTime()
    var sh;
    sh=setInterval(FreshTime,1000);
    </script>

    当前时间获取:

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>当前系统时间</title>
    <link rel="stylesheet" href="style.css"  />
    <script language="javascript" type="text/javascript">
    
      window.onload = function(){
        showTime();
      }
      function checkTime(i){  //补位处理
          if(i<10){
             i="0"+i;       
          }
              return i; 
      }
      function showTime(){
        var mydate=new Date();
        var year=mydate.getFullYear();
        var month=mydate.getMonth()+1 ;
        var day=mydate.getDate();
        var h=mydate.getHours();
        var m=mydate.getMinutes();
        var s=mydate.getSeconds()
        ;
        m=checkTime(m);
        s=checkTime(s);
    
        var weekday=new Array(7)
        weekday[0]="星期日"
        weekday[1]="星期一"
        weekday[2]="星期二"
        weekday[3]="星期三"
        weekday[4]="星期四"
        weekday[5]="星期五"
        weekday[6]="星期六"
    
        document.getElementById("show").innerHTML=""+year+"年"+month+"月"+day+"日 "+  weekday[mydate.getDay()] +h+":"+m+":"+s;
        t=setTimeout('showTime()',500);
      }
    </script>
    </head>
    <body>
    <div class="content1">
      <div id="show">显示时间的位置</div>
    </div>
    </body>
    </html>
    

      

  • 相关阅读:
    http经典解析
    js实现canvas保存图片为png格式并下载到本地
    你所不知的 CSS ::before 和 ::after 伪元素用法
    js自动下载
    CSS 实现隐藏滚动条同时又可以滚动
    checkbox与文字对齐
    利用html2canvas截图,得到base64上传ajax
    bootstrap-datepicker简单使用
    移动端禁止滚动
    h5移动网页唤起App
  • 原文地址:https://www.cnblogs.com/td-tkzc/p/5796187.html
Copyright © 2020-2023  润新知