1. New java. util. Date ()
2. Calendar c = calendar. getinstance ();
C. settime (New java. util. Date ());
Int year = C. Get (calendar. year );
Int month = C. Get (calendar. month) + 1;
Int day = C. Get (calendar. day_of_month );
Int hour = C. Get (calendar. hour_of_day );
Int minute = C. Get (calendar. Minute );
Int second = C. Get (calendar. Second );
3. Date = new date ();
Date. gethours ();
Date. getseconds ();
4. Instance
//--------------------------------------------
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 );
}
}
//--------------------------------------------
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 get some more specific date rows
You can view the calendar class of the API for data.
For example:
Package test;
Import java. Text. dateformat;
Import java. Text. simpledateformat;
Import java. util. calendar;
Import java. util. date;
Public class nowstring {
Public static void main (string [] ARGs ){
Calendar c = calendar. getinstance ();
Date = C. gettime ();
String STR = new simpledateformat ("yyyy-mm-dd"). Format (date );
System. Out. println (STR );
String indate = "2008-09-01 ";
Int I = indate. compareto (STR); // compare the size of two dates
If (I> 0 ){
System. Out. println ("valid:" + I );
} Else {
System. Out. println ("invalid:" + I );
}
}
}
5. The instance can be obtained through the following methods on the JSP page:
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 ;}