public class Date extends Object implements Cloneable, Comparable<Date>, Serializable
This class represents a specific time in milliseconds since the epoch. The epoch is 1970, January 1 00:00:00.0000 UTC.
Date
is intended to reflect universal time coordinate (UTC),
but this depends on the underlying host environment. Most operating systems
don't handle the leap second, which occurs about once every year or
so. The leap second is added to the last minute of the day on either
the 30th of June or the 31st of December, creating a minute 61 seconds
in length.
The representations of the date fields are as follows:
Prior to JDK 1.1, this class was the sole class handling date and time
related functionality. However, this particular solution was not
amenable to internationalization. The new Calendar
class should now be used to handle dates and times, with Date
being used only for values in milliseconds since the epoch. The
Calendar
class, and its concrete implementations, handle
the interpretation of these values into minutes, hours, days, months
and years. The formatting and parsing of dates is left to the
DateFormat
class, which is able to handle the different
types of date format which occur in different locales.
Calendar
,
GregorianCalendar
,
Serialized FormConstructor and Description |
---|
Date()
Creates a new Date Object representing the current time.
|
Date(long time)
Creates a new Date Object representing the given time.
|
Modifier and Type | Method and Description |
---|---|
boolean |
after(Date when)
Tests if this date is after the specified date.
|
boolean |
before(Date when)
Tests if this date is before the specified date.
|
int |
compareTo(Date when)
Compares two dates.
|
boolean |
equals(Object obj)
Compares two dates for equality.
|
long |
getTime()
Gets the time represented by this object.
|
int |
hashCode()
Computes the hash code of this
Date as the
XOR of the most significant and the least significant
32 bits of the 64 bit milliseconds value. |
void |
setTime(long time)
Sets the time which this object should represent.
|
String |
toString()
Returns a string representation of this date using
the following date format:
|
public Date()
public Date(long time)
time
- the time in milliseconds since the epoch.public boolean after(Date when)
when
- the other datepublic boolean before(Date when)
when
- the other datepublic int compareTo(Date when)
compareTo
in interface Comparable<Date>
when
- the other date.public boolean equals(Object obj)
public long getTime()
public int hashCode()
Date
as the
XOR of the most significant and the least significant
32 bits of the 64 bit milliseconds value.public void setTime(long time)
time
- the time in milliseconds since the epoch.public String toString()
Returns a string representation of this date using the following date format:
day mon dd hh:mm:ss zz yyyy
where the fields used here are:
day
-- the day of the week
(Sunday through to Saturday).
mon
-- the month (Jan to Dec).
dd
-- the day of the month
as two decimal digits (01 to 31).
hh
-- the hour of the day
as two decimal digits in 24-hour clock notation
(01 to 23).
mm
-- the minute of the day
as two decimal digits (01 to 59).
ss
-- the second of the day
as two decimal digits (01 to 61).
zz
-- the time zone information if available.
The possible time zones used include the abbreviations
recognised by parse()
(e.g. GMT, CET, etc.)
and may reflect the fact that daylight savings time is in
effect. The empty string is used if there is no time zone
information.
yyyy
-- the year as four decimal digits.
The DateFormat
class should now be
preferred over using this method.