Show dynamic time in JSP page

Source: Internet
Author: User

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] 
  1. <script language=javascript>
  2. var timerid = null;
  3. var timerrunning = false;
  4. function Stopclock () {
  5. if (timerrunning)
  6. Cleartimeout (Timerid);
  7. Timerrunning = false;
  8. }
  9. function Startclock () {
  10. Stopclock ();
  11. Showtime ();
  12. }
  13. function Showtime () {
  14. var now = new Date ();
  15. Document.clock.thetime.value = Now.tostring ();
  16. Timerid = SetTimeout ("Showtime ()", 1000);
  17. Timerrunning = true;
  18. }
  19. </script>

Use the following code in body to display the time.

[HTML] 
  1. <body onload="Startclock ()">
  2. <form name=clock >
  3. <input name=thetime style="Font-size:9pt;color: #000000; border:0" size=>
  4. </form>
  5. </body>


Note: In JavaScript code, Startclock () and Stopclock () Two functions can be removed from the onload and changed to

[HTML]
    1. Onload="Showtime ()"

You can do it.

Show dynamic time in JSP page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.