JSP显示系统时间

JSP页面中使用JavaScript获取系统时间,如下代码:

  
  
  
  
  1. <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> 
  2. <
  3. String path = request.getContextPath(); 
  4. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 
  5. %> 
  6. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
  7. <html> 
  8.   <head> 
  9.     <base href="<%=basePath%>"> 
  10.     <title>SysTime - www.cxybl.com</title> 
  11.     <meta http-equiv="pragma" content="no-cache"> 
  12.     <meta http-equiv="cache-control" content="no-cache"> 
  13.     <meta http-equiv="expires" content="0">     
  14.     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 
  15.     <meta http-equiv="description" content="This is my page"> 
  16.     <script language="JavaScript" type="text/javascript"> 
  17.     function showTime(){ 
  18.         var now=new Date; 
  19.         document.getElementById("dd").innerHTML=now.getFullYear() 
  20.         +"年"+(now.getMonth()+1) 
  21.         +"月"+now.getDate() 
  22.         +"日"+now.getHours() 
  23.         +":"+now.getMinutes()+":"+now.getSeconds(); 
  24.         setTimeout("showTime()","1000"); 
  25.     } 
  26. </script> 
  27. </head> 
  28.   <body onload="showTime()">  
  29.     <div id=dd></div> 
  30. </body>  
  31. </html> 

 

你可能感兴趣的:(JavaScript,jsp)