JSP頁面中使用JavaScript擷取系統時間,如下代碼:
- <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
- <%
- String path = request.getContextPath();
- String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
- %>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <base href="<%=basePath%>">
- <title>SysTime - www.cxybl.com</title>
- <meta http-equiv="pragma" content="no-cache">
- <meta http-equiv="cache-control" content="no-cache">
- <meta http-equiv="expires" content="0">
- <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
- <meta http-equiv="description" content="This is my page">
- <script language="JavaScript" type="text/javascript">
- function showTime(){
- var now=new Date;
- document.getElementById("dd").innerHTML=now.getFullYear()
- +"年"+(now.getMonth()+1)
- +"月"+now.getDate()
- +"日"+now.getHours()
- +":"+now.getMinutes()+":"+now.getSeconds();
- setTimeout("showTime()","1000");
- }
- </script>
- </head>
- <body onload="showTime()">
- <div id=dd></div>
- </body>
- </html>