The JSP page implementation shows the current date time, we can use two ways to achieve:
1. By adding Java code implementations to the JSP page, the main code looks like this
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 DateTime:<%=time%> This displays the formatted date time, and can be formatted differently in SimpleDateFormat according to our needs
2. Through JS implementation.
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 + "years" + month + "Month" + Date + "Day" + strdate + "" + Hour + ":" + Minute +
":" + second;
SetTimeout ("Showtime ();", 1000); }
Then we introduce this JS in the JSP page,
The method Showtime () in the call can get the current time
The above is a small series for everyone to bring the JSP page two ways to show the current time of the simple example of all the content, I hope that we support cloud-Habitat Community ~