The most time class used in Java is java.util.Date,
Because the date class takes GetYear (), GetMonth () and other methods of obtaining the year, month, and day obsolete,
So use calendar to get the date format of the year, month, day, week and more commonly used
Note: The following code has been tested in jdk1.6, other versions may be used differently, please note!
Conversion between date and string
/***/newnew SimpleDateFormat ("yyyy-mm-dd" = = Formatter.parse (datestring);
The interaction between date and calendar
/***/ Calendar= calendar.getinstance (); Cal.settime (New = Cal.gettime ();
Use the calendar to get the year, month, week, day, hour, and other time domains
/***/cal.get (calendar.year); Cal.get (Calendar.month); Cal.get (calendar.week_of_ MONTH); Cal.get (calendar.day_of_month);
To add or subtract time
/***/1); System.out.println (Cal.gettime ());
Calculate the day of the week for a given date
calendarcal = calendar.getinstance (); Cal.set (2016,08,01new string[] {"SUNDAY", "MONDAY", "Tuesday", "Wednesday", "Thursday", "FRIDAY", "SATURDAY" -1]);
Common uses for date and calendar in Java