• JavaScript实时显示当前时间的例子


    用javascript代码在当前页面中实时显示当前时间。
    代码如下:

    <html>
    <head> 
    <title>JavaScript 实时显示当前时间-www.jbxue.com</title> 
    </head> 
    <body> 
    <script language="javascript"> 
    function showtime() 
    { 
    var today,hour,second,minute,year,month,date; 
    var strDate ; 
    today=new Date(); 
    var n_day = today.getDay(); 
    switch (n_day) 
    { 
    case 0:{ 
    strDate = "星期日" 
    }break; 
    case 1:{ 
    strDate = "星期一" 
    }break; 
    case 2:{ 
    strDate ="星期二" 
    }break; 
    case 3:{ 
    strDate = "星期三" 
    }break; 
    case 4:{ 
    strDate = "星期四" 
    }break; 
    case 5:{ 
    strDate = "星期五" 
    }break; 
    case 6:{ 
    strDate = "星期六" 
    }break; 
    case 7:{ 
    strDate = "星期日" 
    }break; 
    } 
    year = today.getYear(); 
    month = today.getMonth()+1; 
    date = today.getDate(); 
    hour = today.getHours(); 
    minute =today.getMinutes(); 
    second = today.getSeconds(); 
    if(month<10) month="0"+month; 
    if(date<10) date="0"+date; 
    if(hour<10) hour="0"+hour; 
    if(minute<10) minute="0"+minute; 
    if(second<10) second="0"+second; 
    document.getElementById('time').innerHTML = year + "" + month + "" + date + "" + strDate +" " + hour + ":" + minute + ":" + second; //显示时间 
    setTimeout("showtime();", 1000); //设定函数自动执行时间为 1000 ms(1 s) 
    } 
    </script>
    <div id="time"></div>
    <script language="javascript"> showtime();</script>
    </body> 
    </html>
  • 相关阅读:
    HTML5智能表单
    HTML表单
    CSS文档统筹
    二分查找/折半查找(C++实现)
    实验6:Problem H: 字符串类(II)
    实验6:Problem G: 字符串类(I)
    实验6:Problem F: 时间和日期类(IV)
    实验6:Problem E: 时间和日期类(III)
    实验6:Problem D: 时间和日期类(II)
    实验6:Problem C: 时间和日期类(I)
  • 原文地址:https://www.cnblogs.com/cfinder010/p/3203191.html
Copyright © 2020-2023  润新知