zoukankan      html  css  js  c++  java
  • js实时显示系统时间

    刚刚在做后台页面最上面要动态显示时间刚写了这个代码

    将这段代码加入<head></head>

    <!--时间显示代码 -->
    <script>
    function clockon(contentDate){    
    var now = new Date();    
    var year = now.getYear();    
    var month = now.getMonth();    
    var date = now.getDate();    
    var day = now.getDay();    
    var hour = now.getHours();    
    var minu = now.getMinutes();    
    var sec = now.getSeconds();   
    var week;     
    month = month+1;    
    if(month<10)month="0"+month;    
    if(date<10)date="0"+date;    
    if(hour<10)hour="0"+hour;    
    if(minu<10)minu="0"+minu;    
    if(sec<10)sec="0"+sec;    
    //var arr_week = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");     
    //week = arr_week[day];    这里显示星期几,我不用所以注释掉了
    var time = "";    
    time = year+"-"+month+"-"+date+"&nbsp;"+hour+":"+minu+":"+sec;  

    //time = year+"-"+month+"-"+date+"week"+hour+":"+minu+":"+sec;   如果需要显示周几的话可以用这句代码
    if(document.all){        
     contentDate.innerHTML=""+time+""    }    
    var timer = setTimeout("clockon(contentDate)",200);            
    }</script>
    <!--时间显示代码 -->

    需要显示时间的地方代码如下:<div align="right" id="contentDate" ></div>

  • 相关阅读:
    合并ts文件
    Typora
    Typora
    OCMock 3 参考
    git 修改上次提交信息 与 撤销此操作.
    git使用技巧
    python获取软件安装列表2222
    【Dojo 1.x】笔记6 配置对象dojoConfig的用处和真身所在
    【Dojo 1.x】笔记目录
    【Dojo 1.x】笔记5 使用本地引用
  • 原文地址:https://www.cnblogs.com/qingsong/p/5031033.html
Copyright © 2011-2022 走看看