zoukankan      html  css  js  c++  java
  • js动态增加秒数(自动,手动)

    //获取当前的日期及时间Date

     var myDate = new Date();  
        myDate.getYear();        //获取当前年份(2位)  
        myDate.getFullYear();    //获取完整的年份(4位,1970-????)  
        myDate.getMonth();       //获取当前月份(0-11,0代表1月)  
        myDate.getDate();        //获取当前日(1-31)  
        myDate.getDay();         //获取当前星期X(0-6,0代表星期天)  
        myDate.getTime();        //获取当前时间(从1970.1.1开始的毫秒数)  
        myDate.getHours();       //获取当前小时数(0-23)  
        myDate.getMinutes();     //获取当前分钟数(0-59)  
        myDate.getSeconds();     //获取当前秒数(0-59)  
        myDate.getMilliseconds();    //获取当前毫秒数(0-999)  
        myDate.toLocaleDateString();     //获取当前日期  
        var mytime=myDate.toLocaleTimeString();     //获取当前时间  
        myDate.toLocaleString( );        //获取日期与时间  

    //js自动1秒增加

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>系统时间</title>
    <script language="javascript" type="text/javascript">
    <!--
    //获得当前时间,刻度为一千分一秒
    var initializationTime=(new Date()).getTime();
    function showLeftTime()
    {
    var now=new Date();
    var year=now.getYear();
    var month=now.getMonth();
    var day=now.getDate();
    var hours=now.getHours();
    var minutes=now.getMinutes();
    var seconds=now.getSeconds();
    document.all.show.innerHTML=""+year+"年"+month+"月"+day+"日 "+hours+":"+minutes+":"+seconds+"";
    //一秒刷新一次显示时间
    var timeID=setTimeout(showLeftTime,1000);
    }
    //-->
    </script>
    </head>
    <body onload="showLeftTime()">
    <label id="show">显示时间的位置</label>

    </body>
    </html>

    //手动增加减少

    var date=new Date();
    $(".time").find('.timeNum').text(date.getHours()+":"+date.getMinutes()+":"+date.getSeconds())

    $("#add").click(function() {
    date.setSeconds(date.getSeconds()+1);
    $(".time").find('.timeNum').text(date.getHours()+":"+date.getMinutes()+":"+date.getSeconds())

    });
    $("#reduce").click(function() {
    date.setSeconds(date.getSeconds()-1);
    $(".time").find('.timeNum').text(date.getHours()+":"+date.getMinutes()+":"+date.getSeconds())

    });

    一分耕耘,一分收获
  • 相关阅读:
    敏捷结果30天之第十七天:找出高效时间,并利用它来处理重要事情
    每天一个linux命令(13):less 命令
    敏捷结果30天之第十九天:你在为谁做事
    每天一个linux命令(6):rmdir 命令
    每天一个linux命令(11):nl命令
    代码重构学习笔记三:重构72招式
    每天一个linux命令(4):mkdir命令
    敏捷结果30天之第二十二天:设计你的一天
    敏捷结果30天之第二十一天:正面失败,吸取教训,改善结果
    每天一个linux命令(8):cp 命令
  • 原文地址:https://www.cnblogs.com/sure2016/p/5868392.html
Copyright © 2011-2022 走看看