1.在頁面上引入jsjavascript
<head> <meta http-equiv="Content-Type" content="text/html; charset=GB18030"> <title>Insert title here</title> <script src="../scripts/jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> $(function() { setInterval(function() { $.get("getTime.jsp?timestamp=" + new Date().getTime(), function( data) { $("#time").html(data); }); }, 1000); }) </script> </head> <body> <div id="time"></div> </body>
2. 後臺getTime.jsp代碼html
<% Date date = new Date(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); out.print(df.format(date)); %>
若是僅僅顯示時間,可單純經過JavaScript獲取本機的時間,自動更新。java