Two methods are available on the jsp page to display simple instances of the current time.

Source: Internet
Author: User

Two methods are available on the jsp page to display simple instances of the current time.

You can display the current date and time on the jsp page in two ways:

1. Add Java code on the jsp page. The main code is as follows:

Java. text. simpleDateFormat simpleDateFormat = new java. text. simpleDateFormat ("yyyy-MM-dd HH: mm: ss"); java. util. date currentTime = new java. util. date (); String time = simpleDateFormat. format (currentTime ). toString (); // put it in the head of the page}

Current date and time: <% = time %> This displays the formatted Date and time. You can set different formats in simpledateformat according to our needs.

2. Implemented through js.

The js Code is as follows: clock. js

Function showtime () {var today; var hour; var second; var minute; var year; var month; var date; var strDate; today = new Date (); var n_day = today. getDay (); switch (n_day) {case 0: {strDate = "Sunday"} break; case 1: {strDate = "Monday"} break; case 2: {strDate = "Tuesday"} break; case 3: {strDate = "Wednesday"} break; case 4: {strDate = "Thursday"} break; case 5: {strDate = "Friday"} break; case 6: {strDate = "Saturday"} break; case 7: {strDate = "Sunday"} break;} year = today. getYear (); month = today. getMonth () + 1; date = today. getDate (); hour = today. getHours (); minute = today. getMinutes (); second = today. getSeconds (); if (month <10) month = "0" + month; if (date <10) date = "0" + date; if (hour <10) hour = "0" + hour; if (minute <10) minute = "0" + minute; if (second <10) second = "0" + second; document. getElementById ('clock '). innerHTML = year + "year" + month + "month" + date + "day" + strDate + "" + hour + ":" + minute + ":" + second; setTimeout ("showtime ();", 1000 );}

Then we introduce this js on the jsp page,

The showtime () method in the call can obtain the current time.

The above is a small series of jsp pages for you to show all the content of the simple instance of the current time in two ways, I hope you can support a lot of help house ~

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.