1. Time to format
//Control the time format, hh indicates a system of Hours,hh is a one-hour system
simpledateforma t sdf = new "Yyyy-mm-dd hh:mm:ss :SSS "
DATE  Date=new Date () .
//Date Turn String
String begin = Sdf.format (date);
//String turn Date
Date ABC =sdf.parse (begin);
2. Modification Time:
Calendar cal = Calendar. getinstance ();
Cal . SetTime (new Date ()); //Get current time ;
cal .add (Calendar. year , +2);// year plus 2
Cal . Add (Calendar. MONTH , +1);// monthly plus 1
Cal.add (Calendar.day_of_month, +7);
Cal.add (Calendar. HOUR , +23);
Cal.add (Calendar. MINUTE , +59);
Cal.add (Calendar. SECOND , +59);
Date D=cal.gettime ();
3, to find the difference in date:
SimpleDateFormat df = New SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");
Date begin = NULL ; //
Date end = NULL ; // if compared to the current time: cal.gettime ()
Try {
begin = Df.parse ("2004-01-02 11:30:24");
end = Df.parse ("2005-01-02 11:31:25");
} catch (ParseException e) {
// TODO auto-generated Catch block
E.printstacktrace ();
}
Long between= (End.gettime ()-begin.gettime ())/1000; //divided by 1000 for conversion into seconds
int int
int int ) (between% (24*3600)/3600);
int minute= (int) (BETWEEN%3600/60); //remaining points
4. Set method default setting 23:59:59
Public void setEndtimeTw0(Date endtime) {
Calendar cal = Calendar. getinstance ();
Cal.settime (Endtime);
Cal.add (Calendar. HOUR , +23);
Cal.add (Calendar. MINUTE , +59);
Cal.add (Calendar. SECOND , +59);
This . Endtime = Cal.gettime ();
}
Java time-related operations