Package Com.etc.usual;import Java.util.calendar;import java.util.date;/** * Public final static int year = 1; * Public final static int MONTH = 2; * Public final static int week_of_year = 3; * Public final static int week_of_month = 4; * Public final static int DATE = 5; * Public final static int day_of_month = 5; * Public final static int day_of_year = 6; * Public final static int day_of_week = 7; * Public final static int day_of_week_in_month = 8; * * * */public class Testcalendar {public static void main (string[] args) {//TODO auto-generated method Stubcalenda R c=calendar.getinstance ();//A way to get a Calendar object System.out.println ("Calendar.year:" +calendar.year); System.out.println ("Calendar.month:" +calendar.month); System.out.println ("Calendar.date:" +calendar.date); System.out.println ("Calendar.week_of_year:" +calendar.week_of_year); System.out.println ("Calendar.week_of_month:" +calendar.week_of_month); System.out.println ("Calendar.day_of_month:" +calendar.day_of_month); SystEm.out.println ("Calendar.day_of_year:" +calendar.day_of_year); System.out.println ("Calendar.day_of_week:" +calendar.day_of_week); See what the Calendar is c=calendar.getinstance (); System.out.println ("\ncalendar:" +c);//output is the details of the time date date=new date (); System.out.println ("Date_gettime:" +date.gettime ()); SetTime: Sets the time of this Calendar with the given Date. Date.setyear (2015-1900); c.settime (date); System.out.println ("\nsettime:" +c); System.out.println ("SetTime:" +c.get (Calendar.year)); System.out.println ("SetTime:" +c.get (1));//Convert Calendar to date getTime (): Returns a Date object that represents this calendar time value, from the calendar element to the current millisecond offset. Date D1 = C.gettime (); System.out.println ("\ngettime:" +d1+ "----" +d1.getyear ()); Set (int field, int value) sets the given Calendar field to the given value. C.set (calendar.year,2000); System.out.println ("\nc.set (calendar.year,2000):" +c.get (Calendar.year)); C.set (calendar.month,11); System.out.println ("C.set (calendar.month,11):" +c.get (calendar.month) + "-------" + (C.gettime ())); C.set ( calendar.month,12); System.out.println ("C.set (calendar.month,12):" +c.get (CaleNdar. MONTH) + "-------" + (C.gettime ())); C.set (calendar.date,20); System.out.println ("C.set (calendar.date,2000):" +c.get (calendar.date) + "-------" + (C.gettime ()));//set (int year, int month, int date) Sets the value of the Calendar field year, month, and Day_of_month. C.set (2020,11,31); System.out.println ("\nc.set (2020,11,31):" +c.gettime ()); Set (int year, int month, int date, int hourofday, int minute, int second)//Set field year, month, Day_of_month, HOUR, MI The values of Nute and SECOND. C.set (2000,1,10,23,55,20); C.set (2017,0,1,7,59,60); Leap seconds: January 1, 2017 7:59 59 seconds System.out.println ("\nc.set (2022,1,10,23,55,20):" +c.gettime ()); Setlenient (Boolean lenient) specifies whether the date/time interpretation is loose. C.setlenient (TRUE); C.set (calendar.month,15);//system.out.println ("\nc.setlenient (true):" +c.gettime ());//c.setlenient (false);// C.set (calendar.month,2);//system.out.println ("\nc.setlenient (false):" +c.gettime ());//getactualmaximum (int field Given the time value for this calendar, returns the maximum value that the specified calendar field might have. Can be divisible by 4 and can not be divisible by 100 is a leap year can be directly divisible by 400 is also leap year System.out.println ("\ngetactualmaximum (calendar.year):"+c.getactualmaximum (calendar.year)); System.out.println ("Getactualmaximum (calendar.month):" +c.getactualmaximum (Calendar.month)); System.out.println ("Getactualmaximum (calendar.date):" +c.getactualmaximum (Calendar.date));// Returns the maximum number of days for the specified year System.out.println ("Getactualmaximum (Calendar.second):" +c.getactualmaximum (Calendar.second));// Returns the maximum number of days in a specified year//getactualminimum (int field) The time value for this calendar is given, returning the minimum value that the specified calendar field might have. System.out.println ("\ngetactualminimum (calendar.year):" +c.getactualminimum (Calendar.year));// The year is System.out.println ("Getactualminimum (calendar.month):" +c.getactualminimum (Calendar.month)) from A.D. System.out.println ("Getactualminimum (calendar.date):" +c.getactualminimum (Calendar.date));//getfirstdayofweek () Get the first day of the week; For example, in the United States, this day is SUNDAY, and in France, this day is MONDAY. System.out.println ("\ngetfirstdayofweek ():" +c.getfirstdayofweek ()); System.out.println ("Calendar.sunday:" +calendar.sunday); System.out.println ("Calendar.monday:" +calendar.monday);//getmaximum (int field) returns the maximum value of the given Calendar field for this calendar instance// GetmaximuM refers to the maximum value for the entire month and day range for example: The number of days is the maximum value between 28,29,30,31//getactualmaximum is the current maximum of the date set. For example: The number of days is the actual number of days of the set month maximum value System.out.println ("\nc.getmaximum (calendar.year):" +c.getmaximum (Calendar.year)); System.out.println ("C.getmaximum (calendar.month):" +c.getmaximum (Calendar.month)); System.out.println ("C.getmaximum (calendar.date):" +c.getmaximum (Calendar.date));//The maximum value depends on the specific parameters of the calendar system instance. That is, the value of the calendar System.out.println ("C.getmaximum (Calendar.second):" +c.getmaximum (Calendar.second)); Add (int field, int amount) Adds or subtracts a specified amount of time for a given calendar field, based on the rules of the calendar. Sun Jan 08:00:00 CST 2017c.add (calendar.year,3); System.out.println ("\nc.add (calendar.year,3):" +c.gettime ()); C.add (calendar.year,-3); System.out.println ("C.add (calendar.year,-3):" +c.gettime ()); C.add (calendar.month,11);//Add 11 months, not set the month//system.out.println ("C.add (calendar.month,11):" +c.gettime ()); C.add (calendar.month,5);//Current is December, added 5 months later, the year plus one, the month becomes May//system.out.println ("C.add (calendar.month,5):" +c.gettime ()); Roll (int field, int amount) adds the specified (signed) amount of time to the specified calendar field without changing the larger field。 C.roll (calendar.year,3); System.out.println ("\nc.roll (calendar.year,3):" +c.gettime ()); C.roll (calendar.month,11);//Add 11 months, not set the month System.out.println ("C.roll (calendar.month,11):" +c.gettime ()); C.roll (calendar.month,5);//Current is December, added 5 months later, the year does not add one, and the month becomes May System.out.println ("C.roll (calendar.month,5):" + C.gettime ()); After (object)) determines whether the time represented by this Calendar is after the time specified by object. Calendar c2=calendar.getinstance (); System.out.println ("\nd1.after (D2):" +c.after (C2)); c:2020 C2:2017//before (object when) determines whether the time represented by this Calendar is before the time specified by object. System.out.println ("D1.before (D2):" +c.before (C2));}}
Calendar.year:1
Calendar.month:2
Calendar.date:5
Calendar.week_of_year:3
Calendar.week_of_month:4
Calendar.day_of_month:5
Calendar.day_of_year:6
Calendar.day_of_week:7
Calendar:java.util.gregoriancalendar[time=1493957201656,arefieldsset=true,areallfieldsset=true,lenient=true, Zone=sun.util.calendar.zoneinfo[id= "Asia/shanghai", offset=28800000,dstsavings=0,usedaylight=false,transitions= 19,lastrule=null],firstdayofweek=1,minimaldaysinfirstweek=1,era=1,year=2017,month=4,week_of_year=18,week_of_ MONTH=1,DAY_OF_MONTH=5,DAY_OF_YEAR=125,DAY_OF_WEEK=6,DAY_OF_WEEK_IN_MONTH=1,AM_PM=1,HOUR=0,HOUR_OF_DAY=12, Minute=6,second=41,millisecond=656,zone_offset=28800000,dst_offset=0]
date_gettime:1493957201657
Settime:java.util.gregoriancalendar[time=1430798801657,arefieldsset=true,areallfieldsset=true,lenient=true, Zone=sun.util.calendar.zoneinfo[id= "Asia/shanghai", offset=28800000,dstsavings=0,usedaylight=false,transitions= 19,lastrule=null],firstdayofweek=1,minimaldaysinfirstweek=1,era=1,year=2015,month=4,week_of_year=19,week_of_ MONTH=2,DAY_OF_MONTH=5,DAY_OF_YEAR=125,DAY_OF_WEEK=3,DAY_OF_WEEK_IN_MONTH=1,AM_PM=1,HOUR=0,HOUR_OF_DAY=12, Minute=6,second=41,millisecond=657,zone_offset=28800000,dst_offset=0]
settime:2015
settime:2015
Gettime:tue 12:06:41 CST----115
C.set (calendar.year,2000): 2000
C.set (calendar.month,11): one-------Tue Dec 12:06:41 CST 2000
C.set (calendar.month,12): 0-------Fri Jan 12:06:41 CST 2001
C.set (calendar.date,2000):-------Sat Jan 12:06:41 CST 2001
C.set (2020,11,31): Thu Dec 12:06:41 CST 2020
C.set (2022,1,10,23,55,20): Sun Jan 08:00:00 CST 2017
Getactualmaximum (calendar.year): 292278994
Getactualmaximum (calendar.month): 11
Getactualmaximum (calendar.date): 31
Getactualmaximum (Calendar.second): 59
Getactualminimum (calendar.year): 1
Getactualminimum (Calendar.month): 0
Getactualminimum (calendar.date): 1
Getfirstdayofweek (): 1
Calendar.sunday:1
Calendar.monday:2
C.getmaximum (calendar.year): 292278994
C.getmaximum (calendar.month): 11
C.getmaximum (calendar.date): 31
C.getmaximum (Calendar.second): 59
C.add (calendar.year,3): Wed Jan 08:00:00 CST 2020
C.add (calendar.year,-3): Sun Jan 08:00:00 CST 2017
C.roll (calendar.year,3): Wed Jan 08:00:00 CST 2020
C.roll (calendar.month,11): Tue Dec 08:00:00 CST 2020
C.roll (calendar.month,5): Fri may 08:00:00 CST 2020
D1.after (D2): True
D1.before (D2): false
Java.util.Calendar