In the class Date
all methods that can accept or return the year, month, date, hour, minute, and second values, the following representation is used:
- The year y is represented by an integer y
- 1900
.
- The month is represented by integers from 0 to One,0 is January , 1 is February, etc., so 11 is December.
- The date (day of January) is usually represented by integers 1 through to .
- The hour is represented by an integer from 0 to . Therefore, from midnight to 1 a.m., the time is 0 , from noon to 1 p.m. the time is 12 points.
- Minutes are represented by an integer of 0 to a normal way.
- The second is represented by an integer of 0 to 60, and a value of 61 is only for leap seconds , although that is only used in Java implementations that actually track leap seconds correctly. It is extremely unlikely that two leap seconds will occur in the same minute as the current introduction of leap seconds, but this specification follows the date and time conventions of ISO C.
In all cases, the arguments given to the method for these purposes do not need to be within the specified scope; For example, you can specify the date as 32 days and interpret it as the same meaning as February 1.
int |
getYear() 已过时。 从 JDK 1.1 开始,由 Calendar.get(Calendar.YEAR) - 1900 取代。
|
int |
getDate() is obsolete. starting from JDK 1.1, Calendar.get(Calendar.DAY_OF_MONTH) replaced by. |
int |
getDay() is obsolete. starting from JDK 1.1, Calendar.get(Calendar.DAY_OF_WEEK) replaced by. |
int |
getHours() is obsolete. starting from JDK 1.1, Calendar.get(Calendar.HOUR_OF_DAY) replaced by. |
int |
getMinutes() is obsolete. starting from JDK 1.1, Calendar.get(Calendar.MINUTE) replaced by. |
int |
getMonth() is obsolete. starting from JDK 1.1, Calendar.get(Calendar.MONTH) replaced by. |
int |
getSeconds() is obsolete. starting from JDK 1.1, Calendar.get(Calendar.SECOND) replaced by. |
Common methods
GetTime
GetTime ()
-
Returns the number of milliseconds that this Date object represents since January 1, 1970 00:00:00 GMT.
-
-
-
Return:
The
-
number of milliseconds that this date represents since January 1, 1970 00:00:00 GMT.
SetTime
settime (Long time)
-
sets this
Date
object to represent
time
a point in time after the millisecond of January 1, 1970 00:00:00 GMT.
-
-
-
Parameters:
-
time
-the number of milliseconds.
Before
before (Date when)
-
Tests whether this date is before the specified date.
-
-
-
Parameters:
-
when
Date
-
Return:
-
Returns if and only if the moment represented by this Date object is earlier than the instant represented by the when
true
false
.
-
Thrown:
-
NullPointerException
-if
when
null.
After
After (Date when)
-
Tests whether this date is after the specified date.
-
-
-
Parameters:
-
when
Date
-
Return:
-
Returns if and only if the moment represented by this Date object is later than the instant represented by the when
true
false
.
-
Thrown:
-
NullPointerException
-if
when
null.
Tostring
toString ()
-
-
Convert this
Date
object to the following form
String
:
Dow Mon dd hh:mm:ss zzz yyyy
which
- Dow is one day of the week (Sun, Mon, Tue, Wed, Thu, Fri, Sat).
- Mon is the month (Jan, Feb, Mar, APR, May, June, Jul, Mar, Sep, Oct, Nov, Dec).
- DD is a day in January (from two) and is displayed as a decimal number.
- The hh is the hour of the day , which is displayed as a two-digit decimal number.
- mm is the minute of the hour (from + to) and is displayed as a two-digit decimal number.
- The SS is the number of seconds in minutes ( up to two) and is displayed in decimal digits.
- zzz is the timezone (and can reflect daylight saving time). The standard time zone abbreviation includes the time zone abbreviation that the method parse recognizes. If you do not provide time zone information, the zzz is empty, meaning that no characters are included at all.
- The yyyy is a year and is displayed as a 4-bit decimal number.
-
-
-
Covered:
-
Object
in the
toString
class
-
-
-
Return:
-
A string representation of this date.
Date in Java