• 日期函数(date)


    1.声明日期

      var date = new Date();

    2.使用函数(从1970年1月1日)

      date.getTime();

      date.valueOf();

      date.now();            返回自1970年1月1日 00:00:00 UTC到当前时间的毫秒数,类型为Number

      new Date();           返回一个日期对象,可以调用getDate(),内容为当前时间

    3.常用方法

      getDate()                获取日(1-31)

      getDay()                 获取星期(0-6)

      getMonth()             获取月(0-11)

      getFullYear()          获取完整年份

      getHours()              获取小时(0-23)

      getMinutes()           获取分钟(0-59)

      getSeconds()         获取秒(0-59)

      getMilliseconds()    获取毫秒(当前)

      getTime()                返回累计毫秒数

    4.倒计时案例

    <style>
    #timeShow{color:#fff;padding:10px 20px;margin:0 auto;filter:alpha(opacity=50);position:fixed;top:40%;1152px;height:40px;margin:0 auto;text-align:center;line-height:40px;font-size:30px;left:50%;margin-left:-596px;background-color:#000;background-color:rgba(0,0,0,.5);}
    </style>
    <div id="timeShow"></div>
    <script>
            showTime();
            function showTime(){
                var curtime = new Date(),//当前时间
                    endtime = new Date("2017/10/30,00:00:00"),//结束时间
                    lefttime = parseInt((endtime.getTime() - curtime.getTime()) / 1000),//秒
                    // d = parseInt(lefttime/(24*60*60)),
                    // h = parseInt(lefttime/(60*60)%24),//%取膜
                    h = parseInt(lefttime/(60*60)),
                    m = parseInt(lefttime/60%60),
                    s = parseInt(lefttime%60);
                    document.getElementById('timeShow').innerHTML ='距离活动开始还剩:'+ h+'小时'+m+'分'+s+'秒';
                    if(lefttime<=0){
                        document.getElementById('timeShow').innerHTML = '';
                        document.getElementById('timeShow').style.display="none";
                    };
                    setTimeout(showTime, 500);
                    console.log(lefttime);
                }

    </script>

  • 相关阅读:
    HTTP协议详解
    【VC++开发实战】迅雷晒密及批量查询流量程序
    C/C++中指针和引用之相关问题研究
    C++类中拷贝构造函数详解
    构造函数为什么不能是虚函数
    High一下!
    文件搜索神器everything 你不知道的技巧总结
    不要被C++“自动生成”所蒙骗
    对象的传值与返回
    深入浅出Node.js (3)
  • 原文地址:https://www.cnblogs.com/water-wf/p/8487702.html
Copyright © 2020-2023  润新知