怎么在JSP中设置动态时间

解决方案 »

  1.   


    <%@ page language="java" contentType="text/html; charset=GBK"
        pageEncoding="GBK"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=GBK">
    <title></title>
    </head>
    <script language="javascript">
    window.onload = function (){
    showTime();
    } function showTime(){
    var xmlDoc = document.getElementById("div2");
    if(xmlDoc.firstChild!=null){
    xmlDoc.firstChild.removeNode();
    }
    var time = new Date();
    time = time.getYear()+"-"+(parseInt(time.getMonth())+1)+"-"+time.getDate()+" "+time.getHours()+":"+time.getMinutes()+":"+time.getSeconds();
    var txtElement = document.createTextNode(time);
    xmlDoc.appendChild(txtElement);
    window.setTimeout("showTime()",1000); }

    </script>
    <body>
    the time:<br/>
    <div id="div2"></div>
    </body>
    </html>