JS countdown, jump module, and comparison date jump module in JSP

Source: Internet
Author: User
Tags date now

1. Preface

This is based on some online materials re-compiled, mainly as a small accumulation of their own use, the original purpose is to make the page automatically Jump within the specified period of time, requests outside the time range are not processed; JS and JSPCode, Put it here for future reference;

2. Code

2.1 countdown Module

This is automatically refreshed every 1 second, and can be slightly modified for other purposes:

<! -- Countdown --> <meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"> <script language = "JavaScript"> function dclock () {var symbol = "March 31"; var deadline = new date ("03/31/2013 11:25:00"); // Standard Time Format var now = new date (); vaR diff =-480-now. gettimezoneoffset (); // time difference between Beijing time and local time var leave = (deadline. gettime ()-now. gettime () + diff * 60000; // gettime () can get the number of milliseconds after 1970, which is a negative var day = math before January 1, 1970. floor (Leave/(1000*60*60*24); // Number of days var hour = math. floor (leave/(1000*3600)-(day * 24); var minute = math. floor (leave/(1000*60)-(day * 24*60)-(hour * 60); var second = math. floor (leave/(1000)-(day * 24*60*60)-(hour * 60*60)-(minute * 60); If (now. gettime () <deadline. gettime () {liveclock. innerhtml = "now" + symbol + "and" + day + "day" + hour + "Hour" + minute + "Minute" + second + "second"; test. innerhtml = "G Ettime: "+ now. gettime () + "Deadline:" + deadline. gettime (); setTimeout ("dclock ()", 1000); // call itself every 1 second} else if (now. gettime ()> deadline. gettime () {liveclock. innerhtml = "end"; setTimeout ("dclock ()", 1000) ;}</SCRIPT> <! -- Countdown --> <body onload = dclock ()> <Div id = liveclock> </div> <Div id = test> </div> </body>

2.2 JS jump

 
<! -- JavaScript begin --> <meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"> <script language = "JavaScript"> function dclock () {var deadline = new date ("05/31/2012 20:30:00"); // the start point of the recording var deadline_2 = new date ("05/31/2012 21:30:00"); // the end of the recording var symbol = "May 31 "; vaR now = new date (); If (now. gettime () <deadline. gettime () {} else if (deadline. gettime () <now. gettime () & now. gettime () <deadline_2.gettime () // C language used to write a <B <C. {// alert (now. gettime (); window. location. href = "http: // localhost/XXX/page.html"; setTimeout ("dclock ()", 1000);} else if (now. gettime ()> deadline_2.gettime () {}}</SCRIPT> <JavaScript end -->

2.3 JSP code

Because JS acquisition is the client time, although the server time can be obtained through interaction, it seems redundant. Here we post the JSP code

 
<% @ Page contenttype = "text/html; charset = UTF-8" Import = "Java. util. *; "%> <% // get the current time in Java. util. date Now = new Java. util. date (); Java. util. date dline = new Java. util. date ("03/01/2012 20:30:00"); Java. util. date dline2 = new Java. util. date ("03/03/2012 21:30:00"); If (now. gettime () <dline. gettime () {} else if (dline. gettime () <now. gettime () & now. gettime () <dline2.gettime () // C language is used to write a <B <C and {response. setstatus (httpservletresponse. SC _moved_permanently); string newlocn = "http: // xxx/page/earthhour/"; response. setheader ("location", newlocn);} else if (now. gettime ()> dline2.gettime () {}%>

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.