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 ~