// This is a simple instance for obtaining the current time, as shown below:
//--------------------------------------------
Import java. util .*;
Import java. text .*;
Public class NowString {
Public static void main (String [] args ){
Date now = new Date ();
DateFormat d = DateFormat. getDateInstance ();
String str = d. format (now );
System. out. println ("Today is" + str );
}
}
//--------------------------------------------
1. Pilot two classes of java. util. *, java. text .*
2. Add a simple sentence: String date = new SimpleDateFormat ("yyyy-MM-dd HH: mm: ss"). format (Calendar. getInstance (). getTime ());
Date is the time you get. The display format can be adjusted randomly according to the format ("yyyy-MM-dd HH: mm: ss, if you want to obtain more specific date row data, you can view the Calendar class of the API.
3. On the JSP page, you can obtain it using the following methods:
Function printDate (){
Var today = new Date ();
Var day = today. getDate ();
Var month = today. getMonth () + 1;
Var year = today. getFullYear (). toString ();
Var box1 = document. stats. Invalid date;
If (month/10) <1 ){
Month = ("0" + month). toString ();
}
If (day/10) <1 ){
Day = ("0" + today. getDate (). toString ();
}
Box1.value = year + "-" + month + "-" + day ;}