Source Address: http://blog.csdn.net/aitcax/article/details/41285305
Static Time:
1. Page header add <% @page import= "Java.util.Date"%>
2. Use <%= new Date (). toString ()%> in the body of the page where the time needs to be displayed.
-------Another: Page Add refresh button------
<input type= "button" onclick= "Javascript:window.location.reload ()" value= "Refresh"/>
Another simple and rude approach:
Write <%= (new Java.util.Date ()) where time is needed. toLocaleString ()%>.
Dynamic Time:
Use JavaScript.
[JavaScript]
- <script language=javascript>
- var timerid = null;
- var timerrunning = false;
- function Stopclock () {
- if (timerrunning)
- Cleartimeout (Timerid);
- Timerrunning = false;
- }
- function Startclock () {
- Stopclock ();
- Showtime ();
- }
- function Showtime () {
- var now = new Date ();
- Document.clock.thetime.value = Now.tostring ();
- Timerid = SetTimeout ("Showtime ()", 1000);
- Timerrunning = true;
- }
- </script>
Use the following code in body to display the time.
[HTML]
- <body onload="Startclock ()">
- <form name=clock >
- <input name=thetime style="Font-size:9pt;color: #000000; border:0" size=>
- </form>
- </body>
Note: In JavaScript code, Startclock () and Stopclock () Two functions can be removed from the onload and changed to
[HTML]
- Onload="Showtime ()"
You can do it.
Show dynamic time in JSP page