java.lang.Object | |
↳ | java.util.Date |
Known Direct Subclasses |
A specific moment in time, with millisecond precision. Values typically come
from currentTimeMillis()
, and are always UTC, regardless of the
system's time zone. This is often called "Unix time" or "epoch time".
Instances of this class are suitable for comparison, but little else.
Use DateFormat
to format a Date
for display to a human.
Use Calendar
to break down a Date
if you need to extract fields such
as the current month or day of week, or to construct a Date
from a broken-down
time. That is: this class' deprecated display-related functionality is now provided
by DateFormat
, and this class' deprecated computational functionality is
now provided by Calendar
. Both of these other classes (and their subclasses)
allow you to interpret a Date
in a given time zone.
Note that, surprisingly, instances of this class are mutable.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Initializes this
Date instance to the current time.
| |||||||||||
This constructor was deprecated
in API level 1.
Use
GregorianCalendar(int, int, int) instead.
| |||||||||||
This constructor was deprecated
in API level 1.
Use
GregorianCalendar(int, int, int, int, int) instead.
| |||||||||||
This constructor was deprecated
in API level 1.
Use
GregorianCalendar(int, int, int, int, int, int)
instead.
| |||||||||||
Initializes this
Date instance using the specified millisecond value.
| |||||||||||
This constructor was deprecated
in API level 1.
Use
DateFormat instead.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
This method was deprecated
in API level 1.
Use code like this instead:
Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
cal.set(year + 1900, month, day, hour, minute, second);
cal.getTime().getTime();
| |||||||||||
Returns if this
Date is after the specified Date.
| |||||||||||
Returns if this
Date is before the specified Date.
| |||||||||||
Returns a new
Date with the same millisecond value as this Date .
| |||||||||||
Compare the receiver to the specified
Date to determine the relative
ordering.
| |||||||||||
Compares the specified object to this
Date and returns if they are equal.
| |||||||||||
This method was deprecated
in API level 1.
Use
Calendar.get(Calendar.DATE) instead.
| |||||||||||
This method was deprecated
in API level 1.
Use
Calendar.get(Calendar.DAY_OF_WEEK) instead.
| |||||||||||
This method was deprecated
in API level 1.
Use
Calendar.get(Calendar.HOUR_OF_DAY) instead.
| |||||||||||
This method was deprecated
in API level 1.
Use
Calendar.get(Calendar.MINUTE) instead.
| |||||||||||
This method was deprecated
in API level 1.
Use
Calendar.get(Calendar.MONTH) instead.
| |||||||||||
This method was deprecated
in API level 1.
Use
Calendar.get(Calendar.SECOND) instead.
| |||||||||||
Returns this
Date as a millisecond value.
| |||||||||||
This method was deprecated
in API level 1.
Use
(Calendar.get(Calendar.ZONE_OFFSET) + Calendar.get(Calendar.DST_OFFSET)) / 60000 instead.
| |||||||||||
This method was deprecated
in API level 1.
Use
Calendar.get(Calendar.YEAR) - 1900 instead.
| |||||||||||
Returns an integer hash code for the receiver.
| |||||||||||
This method was deprecated
in API level 1.
Use
DateFormat instead.
| |||||||||||
This method was deprecated
in API level 1.
Use
Calendar.set(Calendar.DATE, day) instead.
| |||||||||||
This method was deprecated
in API level 1.
Use
Calendar.set(Calendar.HOUR_OF_DAY, hour) instead.
| |||||||||||
This method was deprecated
in API level 1.
Use
Calendar.set(Calendar.MINUTE, minute) instead.
| |||||||||||
This method was deprecated
in API level 1.
Use
Calendar.set(Calendar.MONTH, month) instead.
| |||||||||||
This method was deprecated
in API level 1.
Use
Calendar.set(Calendar.SECOND, second) instead.
| |||||||||||
Sets this
Date to the specified millisecond value.
| |||||||||||
This method was deprecated
in API level 1.
Use
Calendar.set(Calendar.YEAR, year + 1900) instead.
| |||||||||||
This method was deprecated
in API level 1.
Use
DateFormat instead.
| |||||||||||
This method was deprecated
in API level 1.
Use
DateFormat instead.
| |||||||||||
Returns a string representation of this
Date .
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
java.lang.Comparable
|
This constructor was deprecated
in API level 1.
Use GregorianCalendar(int, int, int)
instead.
Constructs a new Date
initialized to midnight in the default TimeZone
on
the specified date.
year | the year, 0 is 1900. |
---|---|
month | the month, 0 - 11. |
day | the day of the month, 1 - 31. |
This constructor was deprecated
in API level 1.
Use GregorianCalendar(int, int, int, int, int)
instead.
Constructs a new Date
initialized to the specified date and time in the
default TimeZone
.
year | the year, 0 is 1900. |
---|---|
month | the month, 0 - 11. |
day | the day of the month, 1 - 31. |
hour | the hour of day, 0 - 23. |
minute | the minute of the hour, 0 - 59. |
This constructor was deprecated
in API level 1.
Use GregorianCalendar(int, int, int, int, int, int)
instead.
Constructs a new Date
initialized to the specified date and time in the
default TimeZone
.
year | the year, 0 is 1900. |
---|---|
month | the month, 0 - 11. |
day | the day of the month, 1 - 31. |
hour | the hour of day, 0 - 23. |
minute | the minute of the hour, 0 - 59. |
second | the second of the minute, 0 - 59. |
Initializes this Date
instance using the specified millisecond value. The
value is the number of milliseconds since Jan. 1, 1970 GMT.
milliseconds | the number of milliseconds since Jan. 1, 1970 GMT. |
---|
This constructor was deprecated
in API level 1.
Use DateFormat
instead.
Constructs a new Date
initialized to the date and time parsed from the
specified String.
string | the String to parse. |
---|
This method was deprecated
in API level 1.
Use code like this instead:
Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
cal.set(year + 1900, month, day, hour, minute, second);
cal.getTime().getTime();
Returns the millisecond value of the specified date and time in GMT.
year | the year, 0 is 1900. |
---|---|
month | the month, 0 - 11. |
day | the day of the month, 1 - 31. |
hour | the hour of day, 0 - 23. |
minute | the minute of the hour, 0 - 59. |
second | the second of the minute, 0 - 59. |
Returns if this Date
is after the specified Date.
date | a Date instance to compare. |
---|
true
if this Date
is after the specified Date
,
false
otherwise.
Returns if this Date
is before the specified Date.
date | a Date instance to compare. |
---|
true
if this Date
is before the specified Date
,
false
otherwise.
Returns a new Date
with the same millisecond value as this Date
.
Date
.Compare the receiver to the specified Date
to determine the relative
ordering.
date | a Date to compare against. |
---|
int < 0
if this Date
is less than the specified Date
, 0
if
they are equal, and an int > 0
if this Date
is greater.
Compares the specified object to this Date
and returns if they are equal.
To be equal, the object must be an instance of Date
and have the same millisecond
value.
object | the object to compare with this object. |
---|
true
if the specified object is equal to this Date
, false
otherwise.
This method was deprecated
in API level 1.
Use Calendar.get(Calendar.DATE)
instead.
Returns the gregorian calendar day of the month for this Date
object.
This method was deprecated
in API level 1.
Use Calendar.get(Calendar.DAY_OF_WEEK)
instead.
Returns the gregorian calendar day of the week for this Date
object.
This method was deprecated
in API level 1.
Use Calendar.get(Calendar.HOUR_OF_DAY)
instead.
Returns the gregorian calendar hour of the day for this Date
object.
This method was deprecated
in API level 1.
Use Calendar.get(Calendar.MINUTE)
instead.
Returns the gregorian calendar minute of the hour for this Date
object.
This method was deprecated
in API level 1.
Use Calendar.get(Calendar.MONTH)
instead.
Returns the gregorian calendar month for this Date
object.
This method was deprecated
in API level 1.
Use Calendar.get(Calendar.SECOND)
instead.
Returns the gregorian calendar second of the minute for this Date
object.
Returns this Date
as a millisecond value. The value is the number of
milliseconds since Jan. 1, 1970, midnight GMT.
This method was deprecated
in API level 1.
Use (Calendar.get(Calendar.ZONE_OFFSET) + Calendar.get(Calendar.DST_OFFSET)) / 60000
instead.
Returns the timezone offset in minutes of the default TimeZone
.
TimeZone
.
This method was deprecated
in API level 1.
Use Calendar.get(Calendar.YEAR) - 1900
instead.
Returns the gregorian calendar year since 1900 for this Date
object.
Returns an integer hash code for the receiver. Objects which are equal return the same value for this method.
Date
's hash.
This method was deprecated
in API level 1.
Use DateFormat
instead.
Returns the millisecond value of the date and time parsed from the
specified String
. Many date/time formats are recognized, including IETF
standard syntax, i.e. Tue, 22 Jun 1999 12:16:00 GMT-0500
string | the String to parse. |
---|
This method was deprecated
in API level 1.
Use Calendar.set(Calendar.DATE, day)
instead.
Sets the gregorian calendar day of the month for this Date
object.
day | the day of the month. |
---|
This method was deprecated
in API level 1.
Use Calendar.set(Calendar.HOUR_OF_DAY, hour)
instead.
Sets the gregorian calendar hour of the day for this Date
object.
hour | the hour of the day. |
---|
This method was deprecated
in API level 1.
Use Calendar.set(Calendar.MINUTE, minute)
instead.
Sets the gregorian calendar minute of the hour for this Date
object.
minute | the minutes. |
---|
This method was deprecated
in API level 1.
Use Calendar.set(Calendar.MONTH, month)
instead.
Sets the gregorian calendar month for this Date
object.
month | the month. |
---|
This method was deprecated
in API level 1.
Use Calendar.set(Calendar.SECOND, second)
instead.
Sets the gregorian calendar second of the minute for this Date
object.
second | the seconds. |
---|
Sets this Date
to the specified millisecond value. The value is the
number of milliseconds since Jan. 1, 1970 GMT.
milliseconds | the number of milliseconds since Jan. 1, 1970 GMT. |
---|
This method was deprecated
in API level 1.
Use Calendar.set(Calendar.YEAR, year + 1900)
instead.
Sets the gregorian calendar year since 1900 for this Date
object.
year | the year since 1900. |
---|
This method was deprecated
in API level 1.
Use DateFormat
instead.
Returns the string representation of this Date
in GMT in the format
"22 Jun 1999 13:02:00 GMT"
.
This method was deprecated
in API level 1.
Use DateFormat
instead.
Returns the string representation of this Date
for the default Locale
.
Returns a string representation of this Date
. The formatting is equivalent to
using a SimpleDateFormat
with the format string "EEE MMM dd HH:mm:ss zzz yyyy",
which looks something like "Tue Jun 22 13:07:00 PDT 1999". While the current default time
zone is used, all formatting and timezone names follow Locale.US
. If you need control
over the time zone or locale, use SimpleDateFormat
instead.