Classar class introduced from JDK1.1 is another different type of date processing class. Imagine that it is a typical calendar hanging on the wall, with many dates and pages you can read.
The Calendar class is the concept of variable domain. Each class element is domain, and these domains behave in the Calendar class as static variables. These variable domains can be obtained or set by the Get / Set class method.
/ / Get the default Calendar instance to set the time
Calendarcal = Calendar.getInstance ();
Interedear = Cal.get (Calendar.Year);
Cal.set (Calendar.month, Calendar.november);
The ADD and Roll methods of the Calendar class provide the ability to convert between the dates. Each method is modified by a parameter variable and a parameter value, and it can be modified by this parameter value of positive or negative numbers. It is only that the add method can overflow to the high order variable domain. For example, if you leave three days from September 3, you will get:
Calendar Cal = Calendar.getInstance ();
Cal.Add (Calendar.date, -3);
// value: Saturday August 31 23:43:19 Edt 2002
However, use the Roll method to roll back to three days:
Calendar Cal = Calendar.getInstance ();
Cal.roll (Calendar.date, -3);
/ / Value: Monday, 18:43:47 Edt 2002
This is why it usually uses the reasons for using the Add method.
There is also a functional method hidden in the subclass of the most common Calendar - theILAPYEAR (determining whether it is a leap year) method.
Calendar Cal = Calendar.getInstance ();
BooleanleApyear = (Gregoriancalendar) .IsLeapyear (2002);
// This value is False
Although it is an example method, the behavior of the IsleApyear method is like a static method, and the parameter pass value of the year is required to give the calendar.
The Java.util.Calendar class seems to be a complex version of the Data class by the function modified by the takeover date. But it also provides additional features, not to mention its international support, making it worth having difficulty curves.