Package day7; import java. util. calendar; import java. util. date;/*** java. util. the Calendar class * is recommended to use the Calendar class * For date and time processing. It is an abstract class and cannot be instantiated. use static Calendar getInstance () to obtain a Calendar Object * int get (int field ): returns the value of the specified Calendar field */public class CalendarDemo {public static void main (String [] args) {Calendar c = Calendar. getInstance (); int y = c. get (Calendar. YEAR); System. out. println (y); // 2013 Date time = c. getTime (); System. out. println (time); // Wed May 15 15:06:17 CST 2013 }}
Common static constants:
YEAR indicates the field number Of The YEAR.
MONTH indicates the number of the MONTH field. The MONTH range is [0, 11].
DATE indicates the day of a month.
DAY_OF_MONTH indicates the day of a month.
DAY_OF_WEEK indicates the day of the week.
HOUR_OF_DAY/HOUR indicates the HOUR
MINUTE indicates the MINUTE
SECOND indicates the SECOND