zoukankan      html  css  js  c++  java
  • 日期函数(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>

  • 相关阅读:
    C#.NET Winform 快速开发平台
    .Net C/S系统开发框架(楚楚原创)
    C# Winform 开发框架
    php导出excel表格超链接
    tp3使用PHPExcel 导出excel
    tp文件上传、表格转数组
    BUG修复记录
    tp3切库问题记录
    个人总结
    初识爬虫(番外篇-python)
  • 原文地址:https://www.cnblogs.com/water-wf/p/8487702.html
Copyright © 2011-2022 走看看