Java.util.Calendar profile is generally written as: import Java.util.Calendar; At the beginning and then in the middle,
Calendar cal = Calendar.getinstance ();
int Year=cal.get (calendar.year);
int Month=cal.get (calendar.month);
Calendar is an abstract class, we can not directly instantiate it, it has a concrete subclass of entity class Java.util.GregorianCalendar, this class is the implementation of our daily Gregorian calendar, or called the solar calendar. We can use the new command to create an instance of it, or use the GetInstance method of the Calendar class to get an instance of it.
Calendar C1 = Calendar.getinstance ();
Calendar C2 = new GregorianCalendar ();
The meaning of the parameters is: year, month, day (, hours, minutes, seconds),
Calendar C3 = New GregorianCalendar (2008, 8, 8, 18, 10, 5);
There are two places to be aware of:
Java represents a month that starts at 0, meaning that the value it uses to represent the month is always 1 smaller than the actual month value. So we're going to say August, that's the value that should be set 8-1=7.
The number of GregorianCalendar hours is 24 hours.
To avoid setting the wrong month for forgetting to handle the 1 difference, and to make the code look more intuitive, it is recommended that you use these constants defined in the Calendar class instead of using numbers to represent the month directly:
January: calendar.january = 0
February: calendar.february = 1
March: Calendar.march = 2
April: Calendar.april = 3
May: Calendar.may = 4
June: Calendar.june = 5
July: calendar.july = 6
August: Calendar.august = 7
September: Calendar.september = 8
October: Calendar.october = 9
November: Calendar.november = 10
December: Calendar.december = 11
If we want to get the values of various properties from the Calendar object, we need to call its get (int field) method, which takes an int parameter and returns the value of the corresponding property based on the value of the given parameter.
Current time: July 22, 2008 13:16:07.421
Property Name: calendar.am_pm
Meaning: Last afternoon logo, morning return calendar.am=0, afternoon return Calendar.pm=1
Test results: 1
Property Name: Calendar.date
Representative meaning: The day of the one months, with Calendar.day_of_month
Test results: 22
Property Name: Calendar.day_of_month
Representative meaning: The day of the one months, with Calendar.date
Test results: 22
Property Name: Calendar.day_of_week
Representative meaning: The day of the week, corresponding to the week, the first days of Sunday, and so on.
Sunday: Calendar.sunday=1
Monday: calendar.monday=2
Tuesday: calendar.tuesday=3
Wednesday: calendar.wednesday=4
Thursday: calendar.thursday=5
Friday: calendar.friday=6
Saturday: calendar.saturday=7
Test results: 3
Property Name: Calendar.day_of_week_in_month
Meaning: The day of the week corresponds to the number of times in the month of the first occurrence
Test results: 4
Property Name: Calendar.day_of_year
Representative meaning: The day of the year
Test results: 204
Property Name: Calendar.hour
Meaning: The number of hours in the 12-hour system, which is expressed as 0 noon and Midnight
Test results: 1
Property Name: Calendar.hour_of_day
Meaning: The number of hours in the 24-hour system, and the midnight representation of 0
Test results: 13
Property Name: Calendar.millisecond
Representative meaning: number of milliseconds
Test results: 421
Property Name: Calendar.minute
Representative Meaning: minutes
Test results: 16
Property Name: Calendar.month
Meaning: month, from 0 to 11 represents 12 months, less than the actual month value of 1
Test results: 6
Property Name: Calendar.second
Representative Meaning: Seconds
Test results: 7
Property Name: Calendar.week_of_month
Meaning: The first few weeks of one months
Test results: 4
Property Name: Calendar.week_of_year
Meaning: The first few weeks of the year
Test results: 30
Property Name: Calendar.year
Representative Meaning: Year
Test results: 2008
Java.util.Calendar Introduction