Java Reference
In-Depth Information
java.util.Calendar
#Calendar()
+get(field: int): int
+set(field: int, value: int): void
+set(year: int, month: int,
dayOfMonth: int): void
+getActualMaximum(field: int): int
+ add(field: int, amount: int): void
+getTime(): java.util.Date
Constructs a default calendar.
Returns the value of the given calendar field.
Sets the given calendar to the specified value.
Sets the calendar with the specified year, month, and date. The month
parameter is 0-based; that is, 0 is for January.
Returns the maximum value that the specified calendar field could have.
Adds or subtracts the specified amount of time to the given calendar field.
Returns a Date object representing this calendar's time value (million
second offset from the UNIX epoch).
Sets this calendar's time with the given Date object.
+setTime(date: java.util.Date): void
java.util.GregorianCalendar
+GregorianCalendar()
+GregorianCalendar(year: int,
month: int, dayOfMonth: int)
+GregorianCalendar(year: int,
month: int, dayOfMonth: int,
hour:int, minute: int, second: int)
Constructs a GregorianCalendar for the current time.
Constructs a GregorianCalendar for the specified year, month, and
date.
Constructs a GregorianCalendar for the specified year, month, date,
hour, minute, and second. The month parameter is 0-based, that
is, 0 is for January.
F IGURE 15.3
The abstract Calendar class defines common features of various calendars.
The get(int field) method defined in the Calendar class is useful for extracting the
date and time information from a Calendar object. The fields are defined as constants, as
shown in Table 15.1.
get(field)
T ABLE 15.1
Field Constants in the Calendar Class
Constant
Description
The year of the calendar.
YEAR
MONTH
The month of the calendar, with 0 for January.
DATE
The day of the calendar.
HOUR
The hour of the calendar (12-hour notation).
HOUR_OF_DAY
The hour of the calendar (24-hour notation).
MINUTE
The minute of the calendar.
SECOND
The second of the calendar.
DAY_OF_WEEK
The day number within the week, with 1 for Sunday.
DAY_OF_MONTH
Same as DATE.
DAY_OF_YEAR
The day number in the year, with 1 for the first day of the year.
WEEK_OF_MONTH
The week number within the month, with 1 for the first week.
WEEK_OF_YEAR
The week number within the year, with 1 for the first week.
AM_PM
Indicator for AM or PM (0 for AM and 1 for PM).
Listing 15.6 gives an example that displays the date and time information for the current time.
L ISTING 15.6 TestCalendar.java
1 import java.util.*;
2
 
 
Search WWH ::




Custom Search