The ~calendar class is an abstract class that provides a number of transitions between a specific moment and a set of calendar fields such as Year,month,day_of_month,hour
Method, and provides methods for manipulating calendar fields (such as getting the date of the next week), which can be expressed instantaneously as a millisecond value, which is a distance from the calendar element (January 1, 1970
Offset of 00:00:00.000)
~ Like other locale-sensitive classes, Calendar provides a class method getinstance, which has obtained a generic object of this type. Calendar's
GETINSTANCEFANGFA Fanhui Yige Calendar object with the current date and time initialized
public static Calendar getinstance ()
Public final Date GetTime ()
Public final void SetTime (date date)
public int get (int field)
Public finalvoid Set (int year,int month,int date)
public boolean befor (Object when)
public boolean aafter (Object when)
public int CompareTo (Calendar anothercalendar)
ImportJava.util.Calendar; Public classCalendardemo { Public Static voidMain (string[] args) {//TODO auto-generated Method StubCalendar Calendar =calendar.getinstance (); System.out.print (Calendar.get (calendar.year)+ "Year"); System.out.print (Calendar.get (calendar.month)+ "Month"); System.out.print (Calendar.get (calendar.date)+ "Day"); System.out.print (Calendar.get (calendar.hour_of_day)+":");//24-hour systemSystem.out.print (Calendar.get (Calendar.minute) + ":"); System.out.println (Calendar.get (Calendar.second)); Calendar.set (Calendar.year,By 2020); System.out.println (Calendar.get (calendar.year)+ "Year"); System.out.println (Calendar.gettimeinmillis ());//the number of seconds that have passed since 1970 to now }}
Java Calendar class