zoukankan      html  css  js  c++  java
  • 当前时间和倒计时效果

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>倒计时效果</title>
    <body>
    当前时间:<p id="p1"></p>
    限时抢购:<p id="p2"></p>
    </body>
        <script type="text/javascript">
            function checkTime(i) {
                if (i<10) {
                    i="0"+i;
                }
                return i;
            }
            window.onload=function () {
    
                var p1=document.getElementById("p1"),
                    p2=document.getElementById("p2");
                showtime1();
                showtime2();
               
            }
            function showtime1() {
                var nowdate=new Date();
                var year=nowdate.getFullYear(),//年份
                    month=nowdate.getMonth()+1,//月份
                    date=nowdate.getDate(),//
                    week=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],
                    day=nowdate.getDay(),//getDay获取0-6
                    h=nowdate.getHours(),
                    h=checkTime(h),
                    m=nowdate.getMinutes(),
                    m=checkTime(m),
                    s=nowdate.getSeconds(),
                    s=checkTime(s);
                p1.innerHTML=year+""+month+""+date+""+week[day]+h+""+m+""+s;
                setTimeout(showtime1, 1000);
            }
     function showtime2() {
                var nowtime=new Date(),
                    endtime=new Date("2020/1/1,00:00:00"),
                    lefttime=parseInt((endtime.getTime()-nowtime.getTime())/1000),
                    d=Math.floor(lefttime/(60*60*24)),
                    h=Math.floor(lefttime/(60*60)%24),
                    m=Math.floor(lefttime/60%60),
                    s=Math.floor(lefttime%60);
                p3.innerHTML=d+""+h+"小时"+m+""+s+"";
                setTimeout(showtime3, 1000);
            }
        </script>
    </head>
    
    </html>
  • 相关阅读:
    hadoop 异常及处理总结-02(小马哥精品)
    Linux环境变量(小马哥推荐)
    Apache Tomcat 8.5 安全配置与高并发优化
    深入理解分布式系统中的缓存架构(上)
    Redis的n种妙用,不仅仅是缓存
    springBoot整合ecache缓存
    Spark Streaming实时处理应用
    Spark 实践
    spark性能调优
    Spark调优
  • 原文地址:https://www.cnblogs.com/yourName/p/9408433.html
Copyright © 2011-2022 走看看