One, the date and string of the reciprocal usage, here need to use SimpleDateFormat
Date date = new Date ();
Set format
SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");
String strdate = Sdf.format (date);
String converted to date type
Date now = Sdf.parse (strdate);
Ii. the reciprocal transfer between date and calendar
Calendar cal = Calendar.getinstance ();
Cal.settime (New Date ());
Date date = Cal.gettime ();
Third, use the calendar to get the year, month, week, day, hour and other time domain
Cal.get (calendar.year);
Cal.get (Calendar.month);
Cal.get (Calendar.week);
Iv. Adding and reducing time
Cal.add (Calendar.month, 1);
Cal.add (calendar.week,2);
Cal.add (CALENDAR.MINUTE,-10);
One parameter of the Add method is the time domain (year, month, week, etc.) that needs to be added and minus, the parameter two-bit variance, the negative number represents the time forward (past), the so-called minus, encounters the cross-domain situation, for example, now is 2012-11, then executes Cal.add (calendar.month,3), Time will automatically change to 2013-02, then roll () method will not, the roll method will push the time to 2012-02, it only for the specified time domain, is not automatically cross-domain
Common uses of the Date and calendar for JAVA